strange caption numbers in cross-references and list-of-figures

I am trying to fit a large figure containing four subfigures into my document. The whole thing is close to a page break, so I decided to split the figure via \ContinuedFloat. So just in case the second half of it can be moved to the next page.

The caption of the large figure with the subfigures is used as a kind of headline and placed on top. The subfigures get captions at the bottom, as well as the next, smaller figure. That is working fine so far.

But the numbers are a mess. The cross-references show, that the subfigures are numbered as "2a" instead of "1a" and so on. The following figure is then "3" instead" of "2". And the list-of-figures displays wrong page numbers for the first two subfigures.

This shows the current situation:

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}

\usepackage[list=true,listformat=simple]{subcaption}
\captionsetup{font=small,labelfont=bf,singlelinecheck=false,within=none}

\usepackage[demo]{graphicx}

\usepackage{cleveref}
\newcommand{\see}[1]{\cref{#1}, \cpageref{#1}}
\newcommand{\sees}[2]{\crefrange{#1}{#2}, \cpagerefrange{#1}{#2}}

\begin{document}
There ist a huge amount of text, but I omitted it, because I was too lazy to type so many sentences.\par
There is some text and more text.\par

\begin{figure}[h]
\caption[short heading for the figure with subfigures]{Something like a heading for this figure containing subfigures}
\label{fig:1}
\vspace{1eM}
\subcaptionbox[short caption, first subfigure]{long caption, first subfigure\label{fig:1A}}{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]{long caption, second subfigure\label{fig:1B}}{\includegraphics[height=7cm]{ExampleB.jpg}}
\end{figure}

\begin{figure}[h]
\ContinuedFloat
\subcaptionbox[short caption, third subfigure]{long caption, third subfigure\label{fig:1C}}{\includegraphics[height=7cm]{ExampleC.jpg}}
\hfill
\subcaptionbox[short caption, fourth subfigure]{long caption, fourth subfigure\label{fig:1D}}{\includegraphics[height=7cm]{ExampleD.jpg}}
\end{figure}

Here is some text in between all these figures.
\begin{figure}[h]
\includegraphics[width=7cm]{Example2.jpg}
\caption{a figure with a wrong number}
\label{fig:2}
\end{figure}

At the end there are some cross-references to these pictures. Since they are floating, it is not really at the end, but that is tolerable for now.\\
\see{fig:1}\\
\see{fig:1A}\\
\see{fig:1D}\\
\see{fig:2}\\
\sees{fig:1A}{fig:1D}\\
\sees{fig:1}{fig:2}\\
\listoffigures
\end{document}


I tried to manage it via \phantomcaption and by redefining the position of the first caption. But since I am completely unaware of what is going on in the background I can't figure it out on my own. I'd really appreciate some help...

• Adding \addtocounter{figure}{-1} between the \vspace and the first \subcaptionbox fixes alle the numbering issues. I suspect that subcaption does something odd with the counters, but I could not track down the misbehaviour yet. (Strangely enough it does not occur in the \ContinuedFloat.) – Ruben Apr 17 '16 at 14:22
• That fix is really a relief since my deadline is coming closer. I am still interested in a 'final' solution though. – fortunecookies Apr 17 '16 at 15:14
• This seems to be a issue with KOMA -- using a normal book or report class, the numbers are correct, without needing \addtocounter{figure}{-1} – user31729 Apr 17 '16 at 16:13
• The problem is the order of the calls. When subcaptions are involved the intended syntax is to strictly place the \caption instruction at the end of the floating environment. The problem in fact disappears when you do \begin{figure}[h]\subcaptionbox...\hfill\subcaptionbox...\caption...\label...\end{figure}. I'll recommend to you to do it that way as it is the most clean fix and you are placing the captions below when you have single figures anyways. – Ruben Apr 17 '16 at 16:13
• documentclass[captions=figureabove]{scrreprt} and done. – Johannes_B Apr 17 '16 at 16:48

With a KOMA-Script class use \captionabove inside a group and remove \vspace{1em}:

\begingroup
\captionabove
[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}%
\label{fig:1}%
\endgroup


Code:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[list=true,listformat=simple]{subcaption}
\captionsetup{font=small,labelfont=bf,singlelinecheck=false,within=none}
\usepackage[demo]{graphicx}
\usepackage{cleveref}
\newcommand{\see}[1]{\cref{#1}, \cpageref{#1}}
\newcommand{\sees}[2]{\crefrange{#1}{#2}, \cpagerefrange{#1}{#2}}

\begin{document}
There ist a huge amount of text, but I omitted it, because I was too lazy to type so many sentences.\par
There is some text and more text.\par

\begin{figure}[ht]
\begingroup
\captionabove
[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}%
\label{fig:1}%
\endgroup
\subcaptionbox
[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox
[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\end{figure}

\begin{figure}[ht]
\ContinuedFloat
\subcaptionbox
[short caption, third subfigure]
{long caption, third subfigure\label{fig:1C}}
{\includegraphics[height=7cm]{ExampleC.jpg}}
\hfill
\subcaptionbox
[short caption, fourth subfigure]
{long caption, fourth subfigure\label{fig:1D}}
{\includegraphics[height=7cm]{ExampleD.jpg}}
\end{figure}

Here is some text in between all these figures.
\begin{figure}[ht]
\includegraphics[width=7cm]{Example2.jpg}
\caption{a figure with a wrong number}
\label{fig:2}
\end{figure}

At the end there are some cross-references to these pictures. Since they are floating, it is not really at the end, but that is tolerable for now.\\
\see{fig:1}\\
\see{fig:1A}\\
\see{fig:1D}\\
\see{fig:2}\\
\sees{fig:1A}{fig:1D}\\
\sees{fig:1}{fig:2}

\listoffigures
\end{document}


Additional explanation why using \captionabove solves this issue:

The counter is usually incremented at \caption (and not at \begin{figure}). While this simple rule is fine having only usual captions, having sub-captions makes all of this more complex since one can have zero to N captions within a figure, and \subcaptionbox (or subfigure environment) must know to which \caption it belongs. Otherwise \ref to a sub-caption would give a wrong result, and the list entry in the List of Figures would be incorrect, too. So when having sub-captions, the figure (or table) counter get sometimes incremented at the caption and sometimes at the sub-caption. For a correct increment of the figure counter the sub-caption must know if it belongs to a main-caption in front of it, or a main-caption coming after it.

Regarding your case: \caption usually means \captionbelow in a document using a KOMA-Script class, and so the first \subcaptionbox increments the figure counter additionally, assuming it belongs to a (future) \caption coming after it. For that reason this will be fixed by using \captionabove instead of \caption (or \captionbelow): This way \subcaptionbox knows it belongs to the (past) \caption typeset in front of it, and this way it does not increment the figure counter anymore.

• Feels less messy than manipulating the counter, thanks for solving my problem! I don't understand why it works though... :D – fortunecookies Apr 19 '16 at 7:19
• @esdd Why \captionabove inside a group, usage of a group seems to be superfluous!? – user2574 Apr 24 '16 at 15:14
• @fortunecookies Since the explanation would be too long for a comment I will add it to esdd's answer right now. – user2574 Apr 24 '16 at 15:38
• @AxelSommerfeldt If I remove the group, the subcaptions are also above of the figures. A possibility without a group would be \captionabove[...]{...} followed by \KOMAoptions{captions=signature}. Thank you for the additional explanations. – esdd Apr 24 '16 at 17:21
• @esdd Upps, yes, you are (of course) right. I tried it without extra group but didn't recognized the incorrect sub-caption position afterwards. – user2574 Apr 24 '16 at 18:01

For a quick fix you can use \addtocounter{figure}{-1} right after the \caption call in your first float to ger the numbering right. In any case I recommend you to wrap this into some macro. Doing so, you are able to control every occurance of this fix at once. In my solution I called this macro \StartSubcaptionsFloat:

\newcommand{\StartSubcaptionsFloat}{\vspace{1em}\addtocounter{figure}{-1}}


As described you would then use it to mark the beginning of your subfigures, e.g.

\begin{figure}
\caption[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}
\StartSubcaptionsFloat
\subcaptionbox[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\label{fig:1}
\end{figure}


If you then want to disable the fix later on you can redefine \StartSubcaptionsFloat to be simply the \vspace adjust, i.e.

\newcommand{\StartSubcaptionsFloat}{\vspace{1em}}


Probabilly your better options are to either change the class as the problem is related to the KOMA classes or to issue \caption at the end of your float. I strongly recommend to go with the last option, i.e. to say

\begin{figure}
\subcaptionbox[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\caption[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}
\label{fig:1}
\end{figure}


as 1) you placed the captions below images in single floats (so it's a matter of consistency), 2) you should not mess with changing the class near the dealine and 3) it's defenetely the cleanest solution.