# Subfloat: How to align subcaption of image to same elevation as other subcaption?

Assumed we have two images with different heights. Both images are aligned to the top via valign=t.

Minimum working example (MWE):

\documentclass{article}
\usepackage{subfig}

\begin{document}

\begin{figure}[h]
\centering
\subfloat[This is image B]{\includegraphics[width=0.45\textwidth, valign=t]{example-image-10x16}}\\
\caption{Caption for images A and B}
\end{figure}

\end{document}


Screenshot of the result:

Description of the issue:

Unfortunately the corresponding caption also moves up to the top with this command.

While both images should remain at the top, the left image caption should move down to the red dashed elevation line of the other caption for better appearance.

How to do so?

Alignment generally involves using baselines, but in this case you need to add a gap between the image and the caption. You will also need to compute the difference between the heights of the two images.

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
\centering
\sbox0{\includegraphics[width=0.45\textwidth]{example-image-16x10}}% measure image
\sbox1{\includegraphics[width=0.45\textwidth]{example-image-10x16}}% measure image
\begin{subfigure}{\wd0}
\usebox0%
\vspace{\dimexpr \ht1-\ht0}% fill space
\caption{This is image A}
\begin{subfigure}{\wd1}
\usebox1
\caption{This is image B}
\end{subfigure}
\caption{Caption for images A and B}
\end{figure}

\end{document}


A solution with minipages and subcaption package:

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

\begin{document}
\lipsum[1]
\begin{figure}[h]
\centering
\begin{minipage}[t]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth, valign=t]{example-image-16x10}
\end{minipage}\hspace{\fill}
\begin{minipage}[t]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth, valign=t]{example-image-10x16}
\end{minipage}
\begin{minipage}[t]{0.45\textwidth}
\captionof{subfigure}{This is image A}
\end{minipage}\hspace{\fill}
\begin{minipage}[t]{0.45\textwidth}
\captionof{subfigure}{This is image B}
\end{minipage}
\caption{Caption for images A and B}
\end{figure}

\end{document}


Edit: Adding parentheses in subcaptions' label and a vertical space between images and captions:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{labelformat = parens}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{figure}[h]
\centering
\begin{minipage}[t]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth, valign=t]{example-image-16x10}
\end{minipage}\hspace{\fill}
\begin{minipage}[t]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth, valign=t]{example-image-10x16}
\end{minipage}
\vspace{5pt}

\begin{minipage}[t]{0.45\textwidth}
\captionof{subfigure}{This is image A}
\end{minipage}\hspace{\fill}
\begin{minipage}[t]{0.45\textwidth}
\captionof{subfigure}{This is image B}
\end{minipage}
\caption{Caption for images A and B}
\end{figure}

\end{document}

• Thanks a lot for your help! Unfortunately the subcaption of the right image is aligned very close to the image now. How to repair this? – Dave Mar 2 at 12:53
• Welcome... See edit. The advantage of minipages in figures and tables (with the help of subcaption package) is the full control of the placements and sizes – koleygr Mar 2 at 13:00

A simple solution with package floatrow:

\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{floatrow}

\begin{document}

\begin{figure}[!h]
\centering