如何使用 subfig 和 floatrow 正確標記子圖?

如何使用 subfig 和 floatrow 正確標記子圖?

我正在使用subfigfloatrow管理子圖。如果沒有floatrow,一切正常,但我需要floatrow輕鬆對齊標題,如subfig手冊所述。

改編手冊第 37 頁上的範例並使用貢薩洛·梅迪納的一些幫助,我有這個代碼:

\documentclass{article}
\usepackage{graphicx,subfig}
\usepackage[heightadjust=all,valign=c]{floatrow}
\usepackage{fr-subfig}

\begin{document}

  \thisfloatsetup{subfloatrowsep=none}
  \begin{figure}[!htbp]
    \captionsetup[subfigure]{justification=centering}
    \floatbox{figure}{%
      \caption{%
        Components of the system: Penguins (\ref{fig:a}), Jumpers (\ref{fig:b}), Thingies (\ref{fig:c}), Cabbages (\ref{fig:d}) and Nuclear Warheads (\ref{fig:e})%
      }\label{fig:x}%
    }{%
  \begin{subfloatrow}%
    \subfloat[Penguins were here and here and here]{%
      \label{fig:a}\includegraphics[height=.1\textheight]{example-image-a}}
    \qquad
    \subfloat[Penguin]{%
      \label{fig:b}\includegraphics[height=.15\textheight]{example-image-b}}
    \qquad
    \subfloat[Penguin]{%
      \label{fig:c}\includegraphics[height=.125\textheight]{example-image-a}}
  \end{subfloatrow}

  \begin{subfloatrow}
    \subfloat[Penguin]{%
      \label{fig:d}\includegraphics[height=.15\textheight]{example-image-b}}
    \qquad
    \subfloat[Penguins were here, there and everywhere!]{%
      \label{fig:e}\includegraphics[height=.2\textheight]{example-image-a}}
  \end{subfloatrow}}
\end{figure}
\ref{fig:x} \ref{fig:a} \ref{fig:c} \ref{fig:e}

\end{document}

子圖編號錯誤

但顯然標題編號有問題。這應該都是數字 1,但它從 4 開始,然後再增加 2。我嘗試將標籤移動到不同的位置,但是,儘管 LaTeX 會告訴我引用已更改,但我仍然得到相同的結果。我也嘗試過刪除.aux檔案等。

這樣做的正確方法是什麼?

答案1

這給出了正確的輸出:

\documentclass{article}
\usepackage{graphicx,subfig}
\usepackage[heightadjust=all,valign=c]{floatrow}
\usepackage{fr-subfig}

\begin{document}

  \thisfloatsetup{subfloatrowsep=qquad}
  \begin{figure}[!htbp]
    \captionsetup[subfigure]{justification=centering}
      \ffigbox{%
  \begin{subfloatrow}[3]%
    \ffigbox[\FBwidth]{\caption{Penguins were here and here and here}\label{fig:a}}{%
      \includegraphics[height=.1\textheight]{example-image-a}}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:b}}{%
      \includegraphics[height=.15\textheight]{example-image-b}}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:c}}{%
      \includegraphics[height=.125\textheight]{example-image-a}}
  \end{subfloatrow}

  \begin{subfloatrow}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:d}}{%
      \includegraphics[height=.15\textheight]{example-image-b}}
    \ffigbox[\FBwidth]{\caption{Penguins were here, there and everywhere!}\label{fig:e}}{%
      \includegraphics[height=.2\textheight]{example-image-a}}
  \end{subfloatrow}%
      }{%
        \caption{Components of the system: Penguins (\ref{fig:a}), Jumpers (\ref{fig:b}), Thingies (\ref{fig:c}), Cabbages (\ref{fig:d}) and Nuclear Warheads (\ref{fig:e})\label{fig:x}}%
    }
\end{figure}
\ref{fig:x} \ref{fig:a} \ref{fig:c} \ref{fig:e}

\end{document}

在此輸入影像描述

問題似乎是將floatrow命令與 subfig結合\subfloat(我猜想使用兩個包中的命令會使計數器以錯誤的方式步進(當每個包獲得控制時,它會步進計數器));一旦僅使用命令完成所有操作floatrow,問題就會消失;請注意,這也會使

  \thisfloatsetup{subfloatrowsep=qquad}

表現如預期,所以現在不需要手動調整(我也在這另一個問題)。

相關內容