0

I have five figures in a chapter. The figure numbers of first 3 figures are correct i.e. 5.1, 5.2 and 5.3 but the figure numbers of next two figures are also 5.3

The structure of first 3 figures is following:

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

Whereas the structure of next two figures is following:

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

It can be noted that in the last two figures, I have used the concept of \ContinuedFloat.

skm
  • 960

2 Answers2

2

Without a complete example, it is impossible to be sure. However, I suspect the problem is the result of the following 2 points:

  • without a \caption or \phantomcaption, \ContinuedFloat will not work;
  • \phantomcaption is defined by caption which you have told subfig ought not be loaded - hence, it is undefined.

Note that compiling non-stop is great but it is not the way to diagnose problems. Ignore errors at your peril. In this case, LaTeX will have failed compilation with an error which would have told you precisely the problem. If you must ignore errors, you have to read the .log assiduously not only when there is an obvious problem, but to find problems of a more subtle variety.

Here's my version of your example, borrowing code from Zarko's efforts:

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

modified MWE

We do not actually need this much. A single figure followed by some filler text, the first part of a figure and the continuation would be quite sufficient to demonstrate the issue:

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

which, if we ignore the errors and carry blithely on, gives us:

modified MWE minimised

which clearly shows the problem: figure 2 on page 2 is numbered 1.

When we try to compile this, compilation fails with the following error:

! Undefined control sequence.
l.24   \phantomcaption

? 

That is, it complains that \phantomcaption is not defined. This is bad because \ContinuedFloat requires a \caption to work. subfig assumes that the first part of a figure will always have a \caption. That caption increments the figure counter. No \caption means no increment. Meanwhile, \ContinuedFloat explicitly prevents the \caption in the second part from incrementing the figure counter.

The solution to this is \phantomcaption which ensures that the counter is incremented. But subfig does not provide this command. caption provides it. But by setting caption=false, we have told subfig that caption is not to be loaded.

For further details, see Axel Sommerfeldt's answer on this topic.

So, there are two obvious options:

  1. set caption=true;
  2. use a real \caption.

In the absence of more details, option 1 seems the better choice. Setting caption=true in the options to subfig resolves the issue nicely:

properly counting figures

Option 2, adding \caption{first part} to the first part of the figure achieves precisely the same result for the second part plus, of course, an additional caption for the first.

If for some reason neither of these are options, the only other choice I can see is to implement something yourself. For example adding the following to your preamble:

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

would allow you to use \phantomfigurecaption in the first part of the figure to achieve roughly the same result. But note that this is a hack and will be much less robust than using one of the options provided by the packages. I do not recommend doing it this way unless you really have no better option.

cfr
  • 198,882
  • thanks for a detailed answer. I tried to set caption=true but it did not help. I will post a complete MWE example in few days. – skm Aug 03 '15 at 14:18
1

Since you didn't provide minimal working example (MWE) I construct my own. I'm pretty sure that it differ a lot form your real document. In it I skip \phantomcaption and ContinuedFloat regardless that they can be cause of your problem (I guess that they work differently as you imagine that they should, but maybe I'm wrong).

This simplified MWE work as expected: counting of figures and sub-figures are continuously incremented: enter image description here

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

This is actualy is not an answer, more is help for yonstruction of your WME, which exhibits your problems. Knowing it, SE community would help you more easily.

Zarko
  • 296,517
  • Thanks for your post. Actually I want to provide MWE but as it a big file where I dont have any problem related to the figure number except at this particular place so, I don't know how can I provide the MWE. – skm Jun 04 '15 at 19:07
  • Just upgrade mine with thing which you missed in it. For example, with packages which are missed, or defined \phantomcaption and \ContinuedFloat. Use lipsum or \blindtext instead of real text and example-image instead real ones. – Zarko Jun 04 '15 at 19:17
  • Sorry for the late reply. I think that the problem is due to the \phantomcaption and ContinuedFloat. Actually, on the same section of a chapter I have 2-3 figures which are using \phantomcaption and ContinuedFloat concept because they consist of several image. Therefore, the \phantomcaption and ContinuedFloat are not able to understand that they are a part of new image. I really don't have any idea what is cause of this behaviour. – skm Jun 13 '15 at 10:14
  • Well, I must confess, that I do not understand, why you need \phantomcaption. As I show you in my MWE, you don't need it at all. I suggest you (again): edit your MWE such that will show your problem. I don't know, how much I miss your expected help. Obviously my answer doesn't help you :-( – Zarko Jun 13 '15 at 10:32
  • This is useful groundwork (+1) but it doesn't reproduce the problem. I take it that \phantomcaption is wanted because the OP wants no caption to be typeset with the first set of sub-figures belonging to a figure which breaks across pages. \ContinuedFloat says that these are further sub-figures belonging to the same overall figure. Your reconstruction would get the numbering wrong: there would be 7 figures rather than 5 and the sub-figure numbering would not be continuous in figure 4/5 or 6/7. So those things are needed - it's just that the OP has disabled the support for \phantomcaption. – cfr Aug 03 '15 at 01:43
  • @cfr, thank you for vote, I vote for your answer too. I carefully read your elaboration in your answer, but I most liked your conclusion :-). In our place we say (literary translated): "He (i.e. OP) like to invent square wheel". For me is not logical to have only sub captions without indication to which figures they belongs, so I wrongly anticipated, that my answer will indicate OP, what readers (lime me) of his paper will expect and how to do this. O.K. at least my answer was useful a bit for preparing of yours :-). – Zarko Aug 03 '15 at 09:51
  • I've never split a figure over a page break. Since \phantomcaption exists, I guess people do it. But I agree that some indication that this is going to happen would be useful. – cfr Aug 03 '15 at 10:54