3

I try to use tufte-latex with subcaptions, which seems generally problematic. A workaround mentioned of compatibility mode for the caption package however, works only partially:

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

% doing this at least the labels are there, but
%   - the caption is bigger
%   - referencing the labels doesn't work
\usepackage{subcaption}
\captionsetup{compatibility=false}

% instead, only to compile without errors
%\newcommand{\subcaption}[1]{}%

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \centering
    \adjustbox{minipage=1.5em,raise=-\height}{\subcaption{}\label{fig:smalla}}%
    \raisebox{-\height}{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
    }
    \adjustbox{minipage=1.5em,raise=-\height}{\subcaption{}\label{fig:smallb}}%
    \raisebox{-\height}{%
  \includegraphics[width=0.4\textwidth]{example-image-b}
    }
    \caption{Two images ---- fig.~\ref{fig:smalla} shows an "A",
      fig.~\ref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}

Output of the above snippet

partially working

Comment out the first part and comment in the second - just to compile without errors. Now the captions have the correct size.

without subcaption at all

  • This is weird! Somehow only the caption label is doing anything. – John Kormylo Mar 3 '17 at 16:01
2

Because of compatibility problems, I replaced \subcaption with my own version. This one does not have to be inside a minipage. OTOH, these subcaptions cannot show up in the \listoffigures (normally they don't anyway).

I also replaced \label with \normallabel for the subcaptions, but continue to use \label for the figure caption. I have no idea what tufte-book is doing to \label or why.

Lastly, I replaced \ref with \hypergetref in the caption. The caption is written into the aux and lof files and \ref doesn't handle expansion well.

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

% doing this at least the labels are there, but
%   - the caption is bigger
%   - referencing the labels doesn't work

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\newcounter{subfigure}[figure]
\renewcommand{\thesubfigure}{\alph{subfigure}}
\newcounter{subtable}[table]
\renewcommand{\thesubtable}{\alph{subtable}}

\makeatletter
\newcommand{\subcaption}{\edef\sub@captype{sub\@captype}%
  \refstepcounter{\sub@captype}%
  (\csname the\sub@captype\endcsname)~}
\makeatother

\AtBeginDocument{\let\normallabel=\label}% must be after hyperef

\begin{document}
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \centering
    \raisebox{-\height}{\subcaption{}\normallabel{fig:smalla}}%
    \raisebox{-\height}{\includegraphics[width=0.4\textwidth]{example-image-a}
    }
    \raisebox{-\height}{\subcaption{}\normallabel{fig:smallb}}%
    \raisebox{-\height}{\includegraphics[width=0.4\textwidth]{example-image-b}
    }
    \caption{Two images ---- fig.~\hypergetref{fig:smalla} shows an "A",
      fig.~\hypergetref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}
  • This makes a good start, thank you! I need to reset the counter in every figure \setcounter{subfigure}{0}. Also I changed \thefigure: \renewcommand{\thissubfigure}{\alph{subfigure}}, change csname accordingly and add \renewcommand{\thesubfigure}{\the\numexpr\value{figure}+1\relax \thissubfigure} to get references as "1a". I didn't get \autoref to work properly up to now. – sdx23 Mar 4 '17 at 11:08
  • I forgot to add the automatic reset. And the \thesubfigure macros were made to be modified. – John Kormylo Mar 4 '17 at 14:24
  • Ah, nice. Also with \def\subfigureautorefname{fig.} autoref does fine. Thanks again, this is much better than my subfigure ansatz (I'd upvote, but can only accept (karma)) – sdx23 Mar 4 '17 at 14:34
3

The package caption, together with subcaption, is not compatible with tufte-book.

You can use subfig, though.

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8]{inputenc}

\usepackage[caption=false]{subfig}

\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum*[1]

\begin{figure}[htb]
\centering
\captionsetup{captionskip=0pt,farskip=0pt,nearskip=0pt}

\vspace*{-\abovecaptionskip}

\subfloat[\label{fig:smalla}]{\qquad}
\includegraphics[width=0.4\textwidth,valign=T]{example-image-a}\hfil
\subfloat[\label{fig:smallb}]{\qquad}
\includegraphics[width=0.4\textwidth,valign=T]{example-image-b}

\caption{Two images ---- fig.~\protect\subref{fig:smalla} shows an "A",
      fig.~\protect\subref{fig:smallb} shows a "B".}
\label{fig:twoimages}

\vspace{\abovecaptionskip}
\end{figure}

Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\subref{fig:smalla} shows an "A",
fig.~\subref{fig:smallb} shows a "B".

\end{document}

Note that \subref should be used for referring to subfloats and that it should be prefixed by \protect if in a moving argument, such as in \caption.

enter image description here

  • This is nice too and less hacky. The only downside is, not having autoref, but I guess that'd be managable. Thank you! – sdx23 Mar 5 '17 at 9:48
  • May I ask why you include \vspace*{-\abovecaptionskip} and \vspace{\abovecaptionskip}? – Henry DeYoung Jan 3 at 18:17
  • @HenryDeYoung I don't remember. Why don't you try omitting them? – egreg Jan 3 at 18:20
0

Now this is some dirty hackery and uses the obsolete subfigure package:

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

\usepackage[FIGTOPCAP,nooneline]{subfigure}
\subfigcaptopadj = -12pt
\subfigcapmargin = -12pt

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \vspace{-12pt}
  \centering
  \subfigure[]{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
  \label{fig:smalla}
    }
  \qquad
  \subfigure[]{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
  \label{fig:smallb}
    }
  \caption{Two images --- fig.~\ref{fig:smalla} shows an "A",
    fig.~\ref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}

Renders as: dirty hackery with subfigure

I'm open to any better solutions, especially since referencing the whole figure does not work any longer and enumeration seems broken.

Edit: yes, A /= B ...

  • Is the obsolete package subfigure really necessary? – user31729 Mar 3 '17 at 12:24
  • To my understanding the superceeding subfig internally uses subcaption and thus ought to have the same issues. At a first try I couldn't reference the subfigures at all. – sdx23 Mar 3 '17 at 13:14
  • No, subfig does not use subcaption internally. (In fact subcaption was developed after subfig was dropped by its author.) – Axel Sommerfeldt Oct 23 '18 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.