三个图形的图形编号相同

三个图形的图形编号相同

我一章中有五幅图。前三幅图的图号是正确的,即 5.1、5.2 和 5.3,但接下来两幅图的图号也是 5.3

前3个数字的结构如下:

        \begin{figure}[!ht]
        \centering
%%image-1
        \subfloat[]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/assignPixels/img1/image1}}
        \subfloat[]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/assignPixels/img1/connectedComps}} 
        \subfloat[]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/assignPixels/img1/supPix}}
        \subfloat[]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/assignPixels/img1/visual}}\\               
        \caption{Assignment of pixels.}
        \label{image:assignSP}
        \end{figure}

而下面两个图的结构如下:

\begin{figure}[]
%%image-1
%%Org image
        \subfloat[Original image]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/assignPixels/img1/image1}}\\
%%Layer-1
        \subfloat[Layer-1, Subgraph-1]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L1_SG1}} 
        \subfloat[Layer-1, Segmentation]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L1_VI}} 
        \subfloat[Layer-1, Saliency]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L1_Sal}}\\      
%%Layer-2       
        \subfloat[Layer-2, Subgraph-1]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L2_SG1}}
        \subfloat[Layer-2, Subgraph-2]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L2_SG2}}  
        \subfloat[Layer-2, Segmentation]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L2_VI}} 
        \subfloat[Layer-2, Saliency]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L2_Sal}}\\      
        \phantomcaption     
        \end{figure}
%%mages on the new page
%%mages on the new page
\begin{figure}[]
        \ContinuedFloat
        \subfloat[Layer-4, Segmentation]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L4_VI}} 
        \subfloat[Layer-4, Saliency]{\includegraphics[width = 2in, height = 3cm, keepaspectratio]{bilder/concepts/GNGhierarchy/img1/L4_Sal}}
        \caption{corresponding maps.}
        \label{image:Hierarchy}
\end{figure}

值得注意的是,在最后两幅图中,我使用了 的概念\ContinuedFloat

答案1

没有完整的例子,就无法确定。不过,我怀疑问题是由于以下两点造成的:

  • 如果没有\caption\phantomcaption\ContinuedFloat则不起作用;
  • \phantomcaptioncaption由您所说的subfig不应加载的内容定义- 因此,它是未定义的。

请注意,不间断地编译很好,但这不是诊断问题的方法。忽视错误会让你陷入危险。在这种情况下,LaTeX 会编译失败,并出现错误,而错误会准确地告诉你问题所在。如果你必须忽略错误,那么你必须认真阅读,.log不仅在出现明显问题时,还要找到更微妙的问题。

这是我的版本,借用了以下代码:扎科的努力

\documentclass{article}
\usepackage[labelsep=space,
labelfont={sf,bf},
textfont=sf,
caption=false]{subfig}
\usepackage{graphicx,kantlipsum}

\begin{document}
\begin{figure}[!ht]
  %        \centering
  %%image-1
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
  \caption{Assignment of pixels 1.}
  \label{image:assignSP1}
\end{figure}
\begin{figure}[!ht]
  %        \centering
  %%image-1
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
  \caption{Assignment of pixels 2.}
  \label{image:assignSP2}
\end{figure}
\begin{figure}[!ht]
  %        \centering
  %%image-1
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
  \caption{Assignment of pixels 3.}
  \label{image:assignSP3}
\end{figure}

\kant[1]

\begin{figure}[!ht]
  %%image-2
  \subfloat[Original image1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-11, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-11, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-11, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\\
  %%Layer-2
  \subfloat[Layer-12, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-12, Subgraph-2] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-12, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-12, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
  \phantomcaption
\end{figure}
\vfill

%%mages on the new page
\begin{figure}[!ht]
  \ContinuedFloat
  \subfloat[Layer-14, Segmentation] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-14, Saliency] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}
  \caption{corresponding maps 1.}
  \label{image:Hierarchy1}
\end{figure}

\kant[2-3]

\begin{figure}[!ht]
  %%image-2
  \subfloat[Original image2] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-21, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-21, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-21, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\\
  %%Layer-2
  \subfloat[Layer-22, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-22, Subgraph-2] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-22, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-22, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
  \phantomcaption
\end{figure}
\vfill

%%mages on the new page
\begin{figure}[!ht]
  \ContinuedFloat
  \subfloat[Layer-24, Segmentation] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}\hfill
  \subfloat[Layer-24, Saliency] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}
  \caption{corresponding maps 2.}
  \label{image:Hierarchy2}
\end{figure}
\end{document}

修正的MWE

我们实际上并不需要这么多。一个图形后面跟着一些填充文本、图形的第一部分和后续部分就足以说明这个问题:

\documentclass{article}
\usepackage[labelsep=space,
labelfont={sf,bf},
textfont=sf,
caption=false]{subfig}
\usepackage{graphicx}

\begin{document}
\begin{figure}[!ht]
  \subfloat[]{\includegraphics[width=\linewidth]{example-image-a}}
  \caption{Assignment of pixels 1.}
  \label{image:assignSP1}
\end{figure}


\begin{figure}[!ht]
  \subfloat[Original image1] {\includegraphics[width=.45\linewidth]{example-image-4x3}}\hfill
  \subfloat[Layer-12, Subgraph-1] {\includegraphics[width=.45\linewidth]{example-image-4x3}}
  \phantomcaption
\end{figure}
\vfill

%%mages on the new page
\begin{figure}[!ht]
  \ContinuedFloat
  \subfloat[Layer-14, Segmentation] {\includegraphics[width=\linewidth]{example-image-b}}\hfill
  \caption{corresponding maps 1.}
  \label{image:Hierarchy1}
\end{figure}

\end{document}

如果我们忽略错误并继续前进,我们将得到:

修正 MWE 最小化

这清楚地表明了问题:第 2 页的图 2 编号为 1。

当我们尝试编译它时,编译失败并出现以下错误:

! Undefined control sequence.
l.24   \phantomcaption

? 

也就是说,它抱怨\phantomcaption未定义。这很糟糕,因为\ContinuedFloat需要\caption工作。subfig假设第一部分figure始终具有\caption。该标题会增加计数器figure。否\caption表示不增加。同时,\ContinuedFloat明确阻止\caption第二部分中的增加figure计数器。

解决此问题的方法是\phantomcaption确保计数器递增。但subfig没有提供此命令。caption提供它。但通过设置caption=false,我们已告知subfig不要caption加载。

有关详细信息,请参阅Axel Sommerfeldt 的回答关于这个话题。

因此,有两个明显的选择:

  1. caption=true;
  2. 使用真正的\caption

在没有更多细节的情况下,选项 1 似乎是更好的选择。caption=true在选项中设置可以subfig很好地解决问题:

正确计算数字

选项 2,添加\caption{first part}到第一部分可以figure实现与第二部分完全相同的结果,当然,还为第一部分添加了一个附加标题。

如果出于某种原因,以上两个都不是选项,那么我能看到的唯一其他选择就是自己实现一些东西。例如,将以下内容添加到您的序言中:

\newcommand*\phantomfigurecaption{\stepcounter{figure}}
\newcommand*\phantomtablecaption{\stepcounter{table}}

允许您\phantomfigurecaption在第一部分中使用figure以获得大致相同的结果。但请注意,这是一种黑客行为,其可靠性远低于使用软件包提供的选项之一。除非您确实没有更好的选择,否则我不建议您这样做。

答案2

由于您没有提供最小工作示例 (MWE),因此我构建了自己的示例。我非常确定它与您的实际文档有很大不同。在其中我跳过了它们,\phantomcaption尽管ContinuedFloat它们可能是导致您出现问题的原因(我猜它们的工作方式与您想象的不同,但也许我错了)。

这种简化的 MWE 工作符合预期:图形和子图形的计数不断增加: 在此处输入图片描述

我的 MWE:

\documentclass{article}
    \usepackage[labelsep=space,
                labelfont={sf,bf},
                textfont=sf,
                caption=false]{subfig}
    \usepackage{graphicx}

    \begin{document}
        \begin{figure}[!ht]
%        \centering
%%image-1
\subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill \subfloat[]{\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
    \caption{Assignment of pixels.}
\label{image:assignSP}
        \end{figure}

\begin{figure}[!ht]
%%image-2
\subfloat[Original image] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-1, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-1, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-1, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\\
%%Layer-2
\subfloat[Layer-2, Subgraph-1] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-2, Subgraph-2] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-2, Segmentation] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-2, Saliency] {\includegraphics[width=0.24\hsize,height=1cm]{example-image}}
        %\phantomcaption
    \caption{Assignment of pixels.}
        \end{figure}
%%mages on the new page
\begin{figure}[!ht]
        %\ContinuedFloat
\subfloat[Layer-4, Segmentation] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-4, Saliency] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}
        \caption{corresponding maps.}
        \label{image:Hierarchy}
\end{figure}
%% my addition
\begin{figure}[!ht]
        %\ContinuedFloat
\subfloat[Layer-4, Segmentation] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}\hfill
\subfloat[Layer-4, Saliency] {\includegraphics[width=0.48\hsize,height=1cm]{example-image}}
        \caption{one more images.}
        \label{image:Hierarchy}
\end{figure}
    \end{document}

这实际上不是一个答案,更多的是帮助你构建 WME,从而展示你的问题。了解这一点,SE 社区会更轻松地帮助你。

相关内容