[Tex/LaTex] Aligned figures and captions on one line

floatsgraphicsvertical alignment

In LaTeX I'm trying to put two figures next to each other, with captions below, where the captions might have unequal numbers of lines in them. The images are bottom-aligned, and the captions are top-aligned.

Figures 8, 9, 10, 11 in the floatrow documentation (p 20) illustrate what I'm hoping to do (using four figures), but the author gives only a partial example, which I cannot get to work:

enter image description here

Can anyone provide a minimum working example that produces Figures 8, 9, 10, 11 as shown in the document. For the filenames of the image files, you can use graphics/fig8.png, graphics/fig9.png, etc. And if it could be the complete LaTeX file, that would be preferable, so I could see the preamble, too.

One last thing: I'm using the style tufte-book — I think it sometimes has conflicts with other packages, but I'll figure that out later. 🙂

Best Answer

You can grab the floatrow documentation code:

\floatsetup[widefloat]{margins=hangleft}
\begin{figure*}%
  \begin{floatrow}[4]
    \ffigbox
      {\caption{Figure~I in the row (\texttt{floatrow}), ``column'' width}%
      \label{fig:row:Dog}}
      {\input{TheDog.picture}}

    \ffigbox[\FBwidth]
      {\caption{Figure~II in the row (\texttt{floatrow}), graphics width}%
      \label{fig:row:WcatI}}
      {\unitlength1.08\unitlength\input{TheCat.picture}}

    \ffigbox[\Xhsize/2]
      {\caption{Figure~III in the row, float's width box has the
       half of the rest space of row}%
      \label{fig:row:mouse}}
      {{\setlength\unitlength{\hsize/58}%
      {\input{Mouse.picture}}}}

    \ffigbox[\Xhsize]
      {\caption{Figure~IV in the row,
      occupies the rest space of row}%
    \label{fig:row:cheese}}
    {\input{Cheese.picture}}
  \end{floatrow}
\end{figure*}%

where the pictures are contained within pictures.tex.

Either way, a package-less approach would be to set each inside a tabular:

enter image description here

\documentclass{article}
\usepackage{lipsum,graphicx}

\begin{document}
\sloppy% Just for this example
\lipsum[1]

\begin{figure}[ht]
  \centering
  \begin{tabular}{ p{2.3cm} p{1.5cm} p{2.7cm} p{2.3cm} }
    \includegraphics[width=\linewidth]{example-image} &
    \includegraphics[width=\linewidth]{example-image-a} &
    \includegraphics[width=\linewidth]{example-image-b} &
    \includegraphics[width=\linewidth]{example-image-c}
    \\[\dimexpr-\normalbaselineskip+\abovecaptionskip]
    \caption{First figure in this row of figures} &
    \caption{Second figure in this row of figures} &
    \caption{Third figure} &
    \caption{Last figure that has a very long caption, stretching multiple rows}
  \end{tabular}
\end{figure}

\lipsum[2]

\end{document}

Each image + caption falls within a fixed-width p-column, with each image set to the width of that column. It's similar to setting the image in the key-value settings for \includegraphics.

This works because images are naturally set on the baseline and take up exactly one line. Moreover, each cell within the tabular is set using a p-column, which has its alignment anchor set to be the baseline of the top line. As a result, the images are bottom-aligned, while the captions are top-aligned.

You can adjust the spacing between the figures and the captions as needed. The same goes for the gap between the images, which default to \tabcolsep in the above example. One could also use tabularx for spreading content out and/or making it stretch-and-fit within the text block.

Related Question