floatrow + caption = 奇怪的行为 + 错误的数字

floatrow + caption = 奇怪的行为 + 错误的数字

在寻找控制子图中垂直对齐的方法时,我决定使用 floatrow 包,但后来发现它的行为相当奇怪。问题在于图形标题,它们可能会消失或计数错误。

例子:

floatrow 标题问题

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

有什么问题?我可以自由地避免使用该包,因此如果有人知道控制子标题+子图垂直和水平对齐的其他方法,那将会有所帮助。

更新

我设法对标题编号,但问题在于子图的高度。所有行的高度都相同,因此如果 A 很小,则其下方会有一个相当大的难看的边距。将其放在\thisfloatsetup第一个之后subfloatrow没有帮助。

在此处输入图片描述

\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

我没有使用该floatrow包,所以我无法在这里提供帮助,但也许只有一个解决方案subcaption才适合您:

在此处输入图片描述

% 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} 

相关内容