1

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:

floatrow caption problem

\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.

enter image description here

\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} 
1

1 Answer 1

1

I don't use the floatrow package, so I can't help here, but maybe a solution with only subcaption would be fine for you:

enter image description here

% arara: pdflatex

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}
Here is Figure \ref{fig:test}:
%
\begin{figure}[h!]
\centering
\caption{Caption that is missing.}\label{fig:test}
    \begin{subfigure}{\textwidth}
        \centering
        \includegraphics[width=5cm]{example-image-a}
        \caption{Test caption a}\label{fig:test1}
    \end{subfigure}

    \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=5cm]{example-image-b}
    \caption{Test caption b}\label{fig:test2}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=5cm]{example-image-c}
    \caption{Test caption c}\label{fig:test3}
    \end{subfigure}
\end{figure}

As you see, figure caption is missing. Besides, Figure \ref{fig:working-caption-test} has got the wrong number.
%
\begin{figure}[h!]
\centering
    \caption{Caption that is not missing.}
    \includegraphics[width=5cm]{example-image-a}
    \label{fig:working-caption-test}
\end{figure}
\end{document} 
4
  • Thanks LaRiFaRi! Do you know how to make 1c aligned with 1b as in my example if they have different heights that are not defined in advance? That's the main reason I started using floatrow. Apr 14, 2014 at 14:06
  • Type texdoc subcaption in your terminal and have a look on the cute animals on page 7. Easiest way would be to bottom align your graphics
    – LaRiFaRi
    Apr 14, 2014 at 14:13
  • My case is not ‘a cat and an elephant’, but more like ‘a bird and an elephant’. Figures must be aligned to top, but captions should remain on the same level. Being more specific, my subfigures are small table-like diagrams and I try to make their headers be next to each other. Apr 14, 2014 at 16:36
  • Would it be an option to set the captions above the figures, as you do for the main caption? Alignment to top can be done by using [t] instead of [b]
    – LaRiFaRi
    Apr 14, 2014 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .