I'm trying to align the tops of two images using the subfigure environment from the subcaption package. Unless I'm misinterpreting the other questions, I believe I have read multiple questions asking the same, Align by the top borders of figures when using subcaption and How to prevent offset in subcaption / subfigure are two examples. The problem is, those answers don't seem to work as I expected, and I still can't get the tops of the images to be aligned.
example:
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{mwe}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\linewidth, height=20em]{example-image-a}
\caption{taller image}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\linewidth, height=15em]{example-image-b}
\caption{shorter image}
\end{subfigure}
\caption{two images}
\end{figure}
\end{document}
For me this generates the following:
I would have expected it to align the tops of the images. How do I do this?
Best Answer
The problem is that
[t]
aligns to the first baseline ([b]
to the last baseline) of the included paragraph, not the top of the content. The baseline of images lies on there lower edge, so[t]
has basically no effect with two images. Lower the images to include the baseline on top or add an empty line above them (using e.g.\vskip 0pt
) to make it work.Further information on this problem can be found in Understanding minipages - aligning at top. Note that
subfigure
uses aminipage
(or the equivialent?) internally.