1

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}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}[h]
    \centering
    \subfloat[This is image A]{\includegraphics[width=0.45\textwidth, valign=t]{example-image-16x10}}\qquad
    \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:

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?

2

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}
    \end{subfigure}\qquad% I prefer \hfil
    \begin{subfigure}{\wd1}
      \usebox1
      \caption{This is image B}
    \end{subfigure}
    \caption{Caption for images A and B}
\end{figure}

\end{document}

demo

1

A solution with minipages and subcaption package:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[export]{adjustbox}
\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}

enter image description here

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[export]{adjustbox}
\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
1

A simple solution with package floatrow:

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

\begin{document}

\begin{figure}[!h]
    \centering
    \floatsetup{heightadjust=all, valign =t}
\ffigbox{\begin{subfloatrow}
    \ffigbox{\caption{This is image A}}{\includegraphics[width=0.45\textwidth]{example-image-16x10}}
    \ffigbox{\caption{This is image B}}{\includegraphics[width=0.45\textwidth]{example-image-10x16}}
\end{subfloatrow}}{\caption{Caption for images A and B}}
\end{figure}

\end{document} 

enter image description here

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.