[Tex/LaTex] Subcaption: Vertical alignment of two images of different vertical size

graphicssubcaptionvertical alignment

I want to place two images of different size next to each other. Both shall have individual subcaptions. Everything works fine. My only question is: how can I center the smaller image vertically with respect to the higher image?

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{subcaption}
\usepackage{tikz}

\begin{document}

\begin{figure}[htbp]
\centering
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[height=.22\textheight]{example-image-a}
\caption{Subcaption left}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[height=.18\textheight]{example-image-b}
\caption{Subcaption right}
\end{subfigure}
\hfill
\caption{Caption}
\end{figure}

\end{document}

Best Answer

You can following the same type of precedures discussed in Subcaption vertical alignment and Vertically align different size images in a figure* environment. That is, capture the size of the larger image, and use its height to adjust the vertical position of the smaller image.

enter image description here

\documentclass{article}
\usepackage{geometry,graphicx}
\geometry{a4paper,margin=1in}
\usepackage{subcaption}
\newsavebox{\largestimage}

\begin{document}

\begin{figure}[htbp]
  \centering
  % Store largest image in a box
  \savebox{\largestimage}{\includegraphics[height=.22\textheight]{example-image-a}}%
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    \usebox{\largestimage}
    \caption{Subcaption left}
  \end{subfigure}
  \quad
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    % Adjust vertical height of smaller image
    \raisebox{\dimexpr.5\ht\largestimage-.5\height}{%
      \includegraphics[height=.18\textheight]{example-image-b}}
    \caption{Subcaption right}
  \end{subfigure}
  \caption{Caption}
\end{figure}

\end{document}

The vertical adjustment is 50% of the height of the larger image minus 50% of the height of the smaller image. Technically this gives 50% of the vertical whitespace around the smaller image... vertically centering it with respect to the larger one.

Related Question