副标题和 \hrulefill 的图片编号错误

副标题和 \hrulefill 的图片编号错误

我在/journal 文档类subfigures中遇到了问题。我正在使用该包来使用子图,并希望用它来将图与文本分开。IEEEtransubcaption\hrulefill

不知何故,\hrulefillsubfigures似乎在某种程度上互相冲突,即subfigure带有的下一个数字\hrulefill将跳过一个数字。

我将其缩减为 MWE。如果我注释掉\hrulefill第 16 行,则图号是正确的。此外,如果我不在subfigures此示例中使用,则图号将是正确的。

有没有其他方法可以让水平线出现在图表标题的上方/下方?而且不会破坏图表计数?

\documentclass[journal,a4paper]{IEEEtran}

\usepackage[utf8]{inputenc}
\usepackage[T5,T1]{fontenc}

\usepackage{subcaption}                             % Subfigures
\usepackage{hyperref}

\usepackage{mwe}                                    % <- For dummy images
\usepackage{lipsum}


\begin{document}\lipsum[1]

\begin{figure}[!b]%
    \hrulefill
    \caption{Figure with subfigures. Has the number 1.}%
    \label{label1}%
    \centering
    \begin{subfigure}[t]{.5\columnwidth}%
        \centering
        \includegraphics[width=.8\columnwidth]{example-image-a}%
    \end{subfigure}%
    \begin{subfigure}[t]{.5\columnwidth}%
        \centering
        \includegraphics[width=.8\columnwidth]{example-image-a}%
    \end{subfigure}%
\end{figure}

\lipsum[1]
\lipsum[1]
\lipsum[1]

\begin{figure}[!b]%
    \hrulefill
    \caption{Figure C. Should have the number 2}%
    \label{label2}%
    \centering
    \includegraphics[width=100px]{example-image-c}%
\end{figure}%

\lipsum[1]

Check the labels: \autoref{label1} is correctly "`Figure 1"'. \autoref{label2} should be "`Figure 2"', but is "`Figure 3"'.

\end{document}

答案1

这很奇怪:-)

我没有追踪那里到底发生了什么,但无论如何,在这种情况下使用它比使用更自然\hrule\hrulefill而且有工作的优势:-)

\documentclass[journal,a4paper]{IEEEtran}

\usepackage[utf8]{inputenc}
\usepackage[T5,T1]{fontenc}

\usepackage{subcaption}                             % Subfigures
\usepackage{hyperref}

\usepackage{mwe}                                    % <- For dummy images
\usepackage{lipsum}


\begin{document}\lipsum[1]

\begin{figure}[!b]%
    \hrule
    \caption{Figure with subfigures. Has the number 1.}%
    \label{label1}%

    \centering
    \begin{subfigure}[t]{.5\columnwidth}%
        \centering
        \includegraphics[width=.8\columnwidth]{example-image-a}%
    \end{subfigure}%
    \begin{subfigure}[t]{.5\columnwidth}%
        \centering
        \includegraphics[width=.8\columnwidth]{example-image-a}%
    \end{subfigure}%
\end{figure}

\lipsum[1]
\lipsum[1]
\lipsum[1]

\begin{figure}[!b]%
    \hrule
    \caption{Figure C. Should have the number 2}%
    \label{label2}%
    \centering
    \includegraphics[width=100px]{example-image-c}%
\end{figure}%

\lipsum[1]

Check the labels: \autoref{label1} is correctly "`Figure 1"'. \autoref{label2} should be "`Figure 2"', but is "`Figure 3"'.

\end{document}

答案2

caption软件包与 不兼容IEEEtran,因此也不兼容subcaption。实际上,文件中有以下警告.log

Package caption Warning: Unsupported document class (or package) detected,
(caption)                usage of the caption package is not recommended.
See the caption package documentation for explanation.

您可以改用subfig带有选项的caption=false

还要注意,图形的标题应该位于底部IEEEtran

\documentclass[journal,a4paper]{IEEEtran}

\usepackage[utf8]{inputenc}
\usepackage[T5,T1]{fontenc}

\usepackage{graphicx}
\usepackage[caption=false]{subfig}
\usepackage{hyperref}

\usepackage{lipsum}


\begin{document}

\lipsum[1]

\begin{figure}[!b]
\hrulefill\par\medskip
\captionsetup[subfloat]{farskip=0pt}

\centering
\hspace*{\fill}%
\subfloat[]{\includegraphics[width=.4\columnwidth]{example-image-a}}%
\hfill
\subfloat[]{\includegraphics[width=.4\columnwidth]{example-image-a}}%
\hspace*{\fill}

\caption{Figure with subfigures. Has the number 1.}
\label{label1}
\end{figure}

\lipsum[1]
\lipsum[1]
\lipsum[1]

\begin{figure}[!b]
\hrulefill\par\medskip

\centering
\includegraphics[width=100px]{example-image-c}

\caption{Figure C. Should have the number 2}
\label{label2}
\end{figure}

\lipsum[1]

Check the labels: \autoref{label1} is correctly "`Figure 1"'. 
\autoref{label2} should be "`Figure 2"', but is "`Figure 3"'.

\end{document}

在此处输入图片描述

相关内容