[Tex/LaTex] two subfigures next to each other aligned on top

columnsfloatssubfloats

I'm trying to place a sequence of images of different height in two columns.
So far I've found I can use the subfigure environment, which I can use in this way:

\documentclass{article}
\usepackage{caption,subcaption}
\usepackage{graphicx} % demo is just for the example

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[b]{.4\textwidth}
\includegraphics[width=\textwidth]{./pic1}

\vspace{1mm}

\includegraphics[width=\textwidth]{./pic2}

\vspace{1mm}

\includegraphics[width=\textwidth]{./pic3}
\end{subfigure}
\hspace{-1mm}
\begin{subfigure}[b]{.4\textwidth}
\includegraphics[width=\textwidth]{./pic4}

\vspace{1mm}

\includegraphics[width=\textwidth]{./pic5}
\end{subfigure}
\caption{The full caption}
\end{figure}

\end{document}

This gives me a figure where the top of the two columns is not aligned, which is what I would want.

outcome of above code

So I need to have this:

enter image description here

Also, the above code works in a separate .tex file but not when I insert it in my document where I want to have it in the end. I get

"Environment subfigure undefined."

I'm using subfloats for all other images there with the package

\usepackage[labelformat=simple]{subfig}

could the problem be that they clash? It would take too much work to move all the old figures to the same subfigure environment, they are all set now.

Alternatively, can the 2-column figure be solved with the subfloat environment?

Best Answer

I have used the subcaption package to get subfigure and subcaption. With the same optional arguments as for minipage the height can be specified for the subfigure box. Here I define \subfigheight so it can easily be changed. Just set to slightly more than the talest stack of pictures (I used \fboxes around the subfigures to see the heights. Then \vfill fills the vertical gaps.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[htb]
  \newcommand\subfigheight{80mm}
  \centering
  \begin{subfigure}[t][\subfigheight][b]{0.4\linewidth}
    \includegraphics[width=\linewidth,height=0.3\linewidth]{example-image}
    \caption{first}
    \vfill
    \includegraphics[width=\linewidth,height=0.3\linewidth]{example-image}
    \caption{next}
    \vfill
    \includegraphics[width=\linewidth,height=0.3\linewidth]{example-image}
    \caption{last}
  \end{subfigure}
  \hspace{2em}
  \begin{subfigure}[t][\subfigheight][b]{0.4\linewidth}
    \includegraphics[width=\linewidth,height=0.5\linewidth]{example-image}
    \caption{next}
    \vfill
    \includegraphics[width=\linewidth,height=0.8\linewidth]{example-image}
    \caption{last}
  \end{subfigure}
  \caption{Overall caption}
  \label{fig:Test}
\end{figure}
\lipsum[2]
\end{document}

enter image description here