2

I am typesetting a document using tufte-book as document class. In the document I have to put figures, both alone and side by side. As this is the case, I use the subfig package to reach this goal, along with the optional [caption=false], as I read somewhere else:

\usepackage[caption=false]{subfig}

Now, I use the following code to insert a single figure:

\begin{figure}%
    \centering%
    \fbox{\includegraphics[width=0.4\linewidth]{img1}}%
    \caption{Caption.}
\end{figure}

And I obtain the following:

correct image, single figure


Otherwise, to put two figures side by side, I use the following code:

\begin{figure}%
    \hfill%
    \subfloat{\fbox{\includegraphics[width=0.4\linewidth]{img1}}}%
    \hfill%
    \subfloat{\fbox{\includegraphics[width=0.4\linewidth]{img2}}}%
    \hfill%
    \caption[][1em]{Caption.}
\end{figure}

The result is the following:

wrong image, two figures


As you may notice, the spacing between the text and the single figure is different from the vertical spacing between the text and the two figures. As a matter of fact, if I didn't specify [][1em] before the \caption command in the latter case, the caption would be in the correct position (namely, where it would be if there was only one figure), but totally misaligned.

It is as if the figure environment begins in the correct place, but the two figures inside are shifted down on the page by 1em or so.

So my questions are: what causes this behaviour? How can I correct it?

1 Answer 1

1

The problem is not with tufte-book and it can be reproduced with article as well.

\documentclass{article}
\usepackage{graphicx}
\usepackage[caption=false]{subfig}

\usepackage{lipsum}

\begin{document}
\lipsum[2]
\begin{figure}[!htp]
\centering
\includegraphics[width=.6\textwidth,height=2cm]{example-image}
\end{figure}
\lipsum[2]
\begin{figure}[!htp]
\centering
\subfloat{\includegraphics[width=0.3\textwidth,height=2cm]{example-image}}
\quad
\subfloat{\includegraphics[width=0.3\textwidth,height=2cm]{example-image}}
\end{figure}
\end{document}

enter image description here

The subfig package defines a length accessible with the key farskip for space to be added on the opposite side to the subcaption. You can set it to zero.

However, if you don't need subcaptions, just don't use \subfloat. I'll show the effect in the next example.

\documentclass{article}
\usepackage{graphicx}
\usepackage[caption=false]{subfig}

\usepackage{lipsum}

\begin{document}
\lipsum[2]
\begin{figure}[!htp]
\centering
\includegraphics[width=.6\textwidth,height=2cm]{example-image}
\end{figure}
\lipsum[2]
\begin{figure}[!htp]
\centering
\captionsetup[subfloat]{farskip=0pt}
\subfloat{\includegraphics[width=0.3\textwidth,height=2cm]{example-image}}%
\quad
\subfloat{\includegraphics[width=0.3\textwidth,height=2cm]{example-image}}
\end{figure}
\lipsum[2]
\begin{figure}[!htp]
\centering
\includegraphics[width=0.3\textwidth,height=2cm]{example-image}%
\quad
\includegraphics[width=0.3\textwidth,height=2cm]{example-image}
\end{figure}
\lipsum[2]
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .