Skip to content

Commit

Permalink
Apply Tufte-LaTeX#145 Fullwidth caption
Browse files Browse the repository at this point in the history
  • Loading branch information
visika committed May 1, 2021
1 parent dceac14 commit 1e5fc8d
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions tufte-common.def
Original file line number Diff line number Diff line change
Expand Up @@ -1176,19 +1176,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 @@ -1219,12 +1229,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 @@ -1297,33 +1307,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

0 comments on commit 1e5fc8d

Please sign in to comment.