4

I have a strange bug where Latex does not continuously count figures. This bug appears only if the caption is above the figure and if the figure includes subfigures. The number of subfigures does not matter, as long as it includes at least one, it is counted as two figures. Please find below a reproducible example in which I show all of these cases.

\documentclass[a4paper,11pt,parskip,oneside,leqno]{scrartcl}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry} 

\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\caption{this is number 1}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{here I have two subfigures with captions}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{second subfigure. I leave out the images for simplicity. This figure is now counted as two and Latex continues with figure 3:}
\end{subfigure}
\end{figure}

\begin{figure}
\caption{this should be figure 2. Here I have no subfigures and this figure is therefore only counted as one}
\centering
\end{figure}

\begin{figure}
\caption{as you can see here. This should be number 3 but we only stepped up one number from the last one so thats ok}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{this one works because the figure above does not use subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{but after this one, it would continue with number 6 because I'm using subfigures again}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{the number of subfigures does not seem to matter}
\end{subfigure}
\end{figure}


\begin{figure}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{as you can see here}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{again a figure with two subfigures to show that:}
\end{subfigure}
\caption{If I put the caption BELOW the figure, the problem does not appear}
\end{figure}

\begin{figure}
\caption{as you can see here}
\centering
\end{figure}


\end{document}

I'd like to have figures with subfigures but I'd like to have the captions on top of the figures and I'd like Latex to count from 1 to N without leaving out numbers ;-) Any help would be appreciated!

5

If you put the captions above the figure content you should tell KOMA-Script about it by using the document class option captions=figureheading, e.g.:

\documentclass[a4paper,11pt,parskip,oneside,leqno,captions=figureheading]{scrartcl}
...

The current version of the caption/subcaption package (and the subfig package) uses this setting, too, to determine if a new figure has started inside the figure environment. (The default setting of KOMA-Script is captions= figuresignature.)

See also: https://tex.stackexchange.com/a/304842/43317

BTW: The upcoming version 3.4 of the caption package will follow a different approach so this example should give a correct numbering even if captions=figureheading is not used. (But one still get incorrect spacing below the caption, so using captions=figureheading will be a good idea anyway.)

3

Using the floatrow package you can fix this by

 \floatsetup{capposition=top}

If you need a caption to be placed below for a single figure you can then use

 \thisfloatsetup{capposition=below}

just before that figure to change the placement.

Sample output

\documentclass[a4paper,11pt,parskip,oneside,leqno]{scrartcl}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}

\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\floatsetup{capposition=top}

\begin{document}

\begin{figure}
\caption{this is number 1}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{here I have two subfigures with captions}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{second subfigure. }
\end{subfigure}
\end{figure}

\begin{figure}
\caption{this should be figure 2. Here I have no subfigures and this figure is therefore only counted as one}
\centering
\end{figure}

\begin{figure}
\caption{as you can see here. This should be number 3 but we only stepped up one number from the last one so thats ok}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{this one works because the figure above does not use subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{many subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{the number of subfigures does not seem to matter}
\end{subfigure}
\end{figure}

\thisfloatsetup{capposition=below}
\begin{figure}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{as you can see here}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{again a figure with two subfigures to show that:}
\end{subfigure}
\caption{If I put the caption BELOW the figure, the problem does not appear}
\end{figure}

\begin{figure}
\caption{as you can see here}
\centering
\end{figure}


\end{document}
  • thanks, that works. But this is a workaround, right? We still don't know why this problem even appears. – Peter Pan Apr 20 '18 at 11:31
  • True. The problem goes away if you use article instead of scrartcl. – Andrew Swann Apr 20 '18 at 14:47
  • @AndrewSwann ...but the problem returns if loading the caption package with option \usepackage[figureposition=b]{caption} (which emulates the default setting in KOMA-Script). – Axel Sommerfeldt May 15 '18 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.