Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullwidth caption #145

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sample-book.pdf
Binary file not shown.
42 changes: 42 additions & 0 deletions sample-book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ \section{Figures and Tables}\label{sec:figures-and-tables}
%\zsavepos{pos:textfig}
\end{figure}


As with sidenotes and marginnotes, a caption may sometimes require vertical
adjustment. The \doccmddef{caption} command now takes a second optional
argument that enables you to do this by providing a dimension \docopt{offset}.
Expand Down Expand Up @@ -765,6 +766,47 @@ \section{Captions}
the algorithm to assume the float has been placed on a recto page---that is, a
page on the right side of a two-page spread.

\paragraph{Full-width captions}\label{par:fullwidth-captions}
To get a full width caption for a figure or table you can use the \texttt{figurefw} and \texttt{tablefw} environments.
Both behave like their \texttt{*} counterparts, but also extend the caption across the full width of the page.
Note that this is useful mostly for full-page figures and tables.
An example with a regular sized figure:

\begin{fullwidth}
\begin{docspec}
\textbackslash begin\{figurefw\}[btp]\\
\qquad \textbackslash includegraphics\{sinewave\}\\
\qquad \textbackslash caption\{This graph shows ....\}\\
\qquad \textbackslash label\{fig:fullwidthsinewave\}\\
\textbackslash end\{figurefw\}
\end{docspec}
\end{fullwidth}

\begin{figurefw}[h]
\includegraphics[width=\linewidth]{sine.pdf}%
\caption{This graph shows $y = \sin x$ from about $x = [-10, 10]$.
\emph{Notice that this figure takes up the full page width and that its caption takes up the full page width as well.}}%
\label{fig:fullcapfig}%
\end{figurefw}%

\begin{tablefw}[h]
\begin{center}
\footnotesize%
\begin{tabular}{ccl}
\toprule
First Column & Second Column & Filler Text \\
\midrule
42 & 23 & Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dictum gravida mauris.\\
17 & 9 & Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.\\
\bottomrule
\end{tabular}
\end{center}
\caption{Example of a really wide table with a wide, left aligned caption.}
\label{tab:wide_table}
\end{tablefw}




\section{Full-width text blocks}

Expand Down
45 changes: 34 additions & 11 deletions tufte-common.def
Original file line number Diff line number Diff line change
Expand Up @@ -1217,19 +1217,29 @@
}

\newcommand{\@tufte@fps}{}
\newcommand{\@tufte@float@fwalign}{}

\newboolean{@tufte@float@star}
\newboolean{@tufte@float@fwcaption}
\newlength{\@tufte@float@contents@width}
\newlength{\@tufte@float@fwwidth}

%%
% Define a float environment to place the captions in the margin space

\newenvironment{@tufte@float}[3][htbp]%
\newenvironment{@tufte@float}[4][htbp]%
{% begin @tufte@float
% Should this float be full-width or just text-width?
\ifthenelse{\equal{#3}{star}}%
{\gsetboolean{@tufte@float@star}{true}}%
{\gsetboolean{@tufte@float@star}{false}}%
\ifthenelse{\equal{#4}{fwcaption}}{%
\setlength{\@tufte@float@fwwidth}{\@tufte@fullwidth}%
\renewcommand{\@tufte@float@fwalign}{t}
}{%
\setlength{\@tufte@float@fwwidth}{\marginparwidth}%
\renewcommand{\@tufte@float@fwalign}{\floatalignment}%
}%
% Check page side (recto/verso) and store detected value -- can be overriden in environment contents
\@tufte@checkoddpage%
\ifthenelse{\boolean{@tufte@odd@page}}%
Expand Down Expand Up @@ -1263,12 +1273,12 @@
\end{lrbox}%
% build the caption box
\begin{lrbox}{\@tufte@caption@box}%
\begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
\ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
\ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
\par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
\end{minipage}%
\end{lrbox}%
\begin{minipage}[\@tufte@float@fwalign]{\@tufte@float@fwwidth}\hbox{}% this is my version
\ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
\ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
\par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
\end{minipage}%
\end{lrbox}%
% now typeset the stored boxes
\begin{fullwidth}%
\begin{minipage}[\floatalignment]{\linewidth}%
Expand Down Expand Up @@ -1341,33 +1351,46 @@
% Redefine the figure environment to place the captions in the margin space

\renewenvironment{figure}[1][htbp]%
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{}}
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{}{}}
{\end{@tufte@float}}


%%
% Redefine the table environment to place the captions in the margin space

\renewenvironment{table}[1][htbp]
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{}}
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{}{}}
{\end{@tufte@float}}


%%
% Full-width figure

\renewenvironment{figure*}[1][htbp]%
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{star}}
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{star}{}}
{\end{@tufte@float}}

%%
% Full-width figure with full width caption

\newenvironment{figurefw}[1][htbp]%
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{star}{fwcaption}}
{\end{@tufte@float}}


%%
% Full-width table

\renewenvironment{table*}[1][htbp]%
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{star}}
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{star}{}}
{\end{@tufte@float}}

%%
% Full-width table with full width caption

\newenvironment{tablefw}[1][htbp]%
{\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{star}{fwcaption}}
{\end{@tufte@float}}

%%
% Full-page-width area
Expand Down