Looking for means to control vertical alignment in subfigures, I decided to use floatrow package, but later found its behavior quite strange. The issue is with figure captions, which may disappear or have a wrong count.
Example:
\documentclass{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}
Here is Figure \ref{fig:test}:
\thisfloatsetup{heightadjust=all,valign=t}
\begin{figure}[H]
\caption{Caption that is missing.} % An error occurs when I place \caption and \label before \end{figure}
\label{fig:test}
\begin{subfigure}{\textwidth}
\centering
\includegraphics[width=5cm]{example-image-a}
\caption{Test caption a}\label{fig:test1}
\vspace{.5cm}
\end{subfigure}
\begin{subfloatrow}
\ffigbox[]
{\includegraphics[width=5cm]{example-image-b}}
{\caption{Test caption b}\label{fig:test1}}
\ffigbox[]
{\includegraphics[width=4.5cm]{example-image-c}}
{\caption{Test caption c}\label{fig:test2}}
\end{subfloatrow}
\end{figure}
As you see, figure caption is missing. Besides, Figure \ref{fig:working-caption-test} has got the wrong number.
\begin{figure}[H]
\caption{Caption that is not missing.}
\includegraphics[width=5cm]{example-image-a}
\label{fig:working-caption-test}
\end{figure}
\end{document}
What can be wrong? I have freedom to avoid using the package, so if anyone knows other ways of controlling subcaption+subfigure vertical and horizontal alignments, that will help.
UPDATE
I managed caption numbering, but the problem is with the heights of subfigures. All rows get the same height, so if A is small, there’ll be a rather large ugly margin beneath it. Placing \thisfloatsetup
after the first subfloatrow
does not help.
\documentclass{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}
Here is Figure \ref{fig:test}:
\thisfloatsetup{heightadjust=all,valign=t}
\begin{figure}[H]
\ffigbox[]{
\begin{subfloatrow}
\ffigbox[]
{\centering\includegraphics[width=2cm]{example-image-a}}
{\subcaption{Test caption a}\label{fig:test1}}
\end{subfloatrow}
\begin{subfloatrow}
\ffigbox[]
{\includegraphics[width=5cm]{example-image-b}}
{\subcaption{Test caption b}\label{fig:test1}}
\ffigbox[]
{\includegraphics[width=4.5cm]{example-image-c}}
{\subcaption{Test caption c (pretty long one xxxxx xxxxxxxx)}\label{fig:test2}}
\end{subfloatrow}
}
{\caption{Caption that was missing.}\label{fig:test}}
\end{figure}
As you see, figure caption is not missing any more and Figure \ref{fig:working-caption-test} has the right number. However, the height of subloatrow with A is bigger that it should
\begin{figure}[H]
\includegraphics[width=5cm]{example-image-a}
\caption{Caption that is not missing.}\label{fig:working-caption-test}
\end{figure}
\end{document}