# [Tex/LaTex] Subfloat vertical alignment in latex

graphicssubfloatsvertical alignment

If I have to pictures of different height and the same width, how can I dock them to the top that both pictures are vertically aligned. This is my code so far:

\begin{figure}[h]
\centering
\subfloat[Part 1]{%
\includegraphics[width=0.4\textwidth]{pic1.png}%
\label{fig:left}%
}
\subfloat[Part 2]{%
\includegraphics[width=0.4\textwidth]{pic2.png}%
\label{fig:middle}%
}
\caption{Stuff will be here.}
\label{fig:default}
\end{figure}


Sub-float package assumes that it is important to vertically align the captions, and therefore typically relies on a baseline alignment of the sub-float content.

Using adjustbox's valign=t option, the image's (the sub-float content) regular baseline alignment could be altered to now be at the top. However, you may also want to insert an appropriately-sized companion for the shorter image... do that by using \vphantom{<larger image>}:

\documentclass{article}

\usepackage{subfig}

\begin{document}

\begin{figure}
\centering

\subfloat[Part 1]{%
\includegraphics[width=0.2\textwidth,valign=t]{example-image-a}%
\subfloat[Part 2]{%
\includegraphics[width=0.2\textwidth,valign=t]{example-image-10x16}%
}

\subfloat[Part 1]{%
\includegraphics[width=0.2\textwidth,valign=t]{example-image-a}%
\vphantom{\includegraphics[width=0.2\textwidth,valign=t]{example-image-10x16}}%