[Tex/LaTex] Numbers keep continuing – Problem with subfig and ContinuedFloat

numberingsubfloats

I have a problem with the numbering in continued subfloats. I just changed my package (subfigure) to subfig because I read that this allows me to continue subfloats on a new page using the command \ContinuedFloat.

However, now I have the problem that the numbering (actually lettering) of subfloats continues, even if I close the figure environment and make a new one (containing subfloats) – see screenshot attached.

This problem happens more than once, but here is an example of code.

edit: I have narrowed it down: every time I use \ContinuedFloat the next normal figure environment will also be a continuation.

\documentclass[a4paper]{scrreprt}
\usepackage{float}
\usepackage{subfig}

\begin{document}

\begin{document}
\begin{figure}[H]   \centering
\subfloat[Sommer während Schwall -- Überblick]
{\includegraphics[width=0.05\textwidth]{HEM_suitability-index.png}
\includegraphics[width=0.85\textwidth]{Drau2/Salmo/ist/SOM/WUA_Asw.png}}
        \caption{Habitatverteilung für den Istzustand im Sommer (Bachforelle) -- Übersicht}
\end{figure}

\begin{figure}[H]   \centering
       \ContinuedFloat 
\subfloat[Sommer während Schwall -- Detail 1 \label{dr:s:ist:d1}]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/SOM/WUA_D1sw.png}}
\subfloat[Sommer w. Schwall -- Detail 2]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/SOM/WUA_D2sw.png}}

\subfloat[Sommer w. Sunk -- Detail 1]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/SOM/WUA_D1su.png}}
\subfloat[Sommer w. Sunk -- Detail 2]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/SOM/WUA_D2su.png}}
        \caption{Habitatverteilung für den Istzustand im Sommer (Bachforelle)}
        \label{dr:s:ist:som}
\end{figure}

\begin{figure}[H]   \centering
         %--- NOT CONTINUEDFLOAT - but it does continue with the letters ---
\subfloat[Winter während Schwall -- Detail 1]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/WIN/WUA_D1sw.png}}
\subfloat[Winter w. Schwall -- Detail 2]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/WIN/WUA_D2sw.png}}

\subfloat[Winter w. Sunk -- Detail 1]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/WIN/WUA_D1su.png}}
\subfloat[Winter w. Sunk -- Detail 2 \label{dr:w:ist:d2}]
{\includegraphics[width=0.49\textwidth]{Drau2/Salmo/ist/WIN/WUA_D2su.png}}
        \caption{Habitatverteilung für den Istzustand im Winter (Bachforelle) }
        \label{dr:s:ist:win}
\end{figure}

\end{document}

I have been using \phantomcaption for when I don't need to display the first caption. That causes no problems in the further numbering.

Help would be much appreciated because I am totally losing my nerves with subfigures.
– Thanks in advance!

Best Answer

Short answer:

Switch to the subcaption package.

Long answer:

The problem comes from a bad interaction between the H placement specifier from the float package and subfig, as the following reduced example shows:

\documentclass[a4paper]{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{subfig}

\begin{document}

\begin{figure}[H]
\centering
\subfloat[test]{\includegraphics[width=3cm]{image1}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image2}}
\caption{First part of a continued float}
\end{figure}

\begin{figure}[H]
\centering
\ContinuedFloat 
\subfloat[test]{\includegraphics[width=3cm]{image3}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image4}}
\caption{Second part of the continued float}
\label{dr:s:ist:som}
\end{figure}

\begin{figure}[H]
\centering
\subfloat[test]{\includegraphics[width=3cm]{image5}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image6}}
\caption{Another independent figure with subfigures}
\label{dr:s:ist:win}
\end{figure}

\end{document}

enter image description here

Removing the H placement specifier fixes the problem with the subfigures, but creates another one:

\documentclass[a4paper]{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{subfig}

\begin{document}

\begin{figure}
\centering
\subfloat[test]{\includegraphics[width=3cm]{image1}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image2}}
\caption{First part of a continued float}
\end{figure}

\begin{figure}
\centering
\ContinuedFloat 
\subfloat[test]{\includegraphics[width=3cm]{image3}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image4}}
\caption{Second part of the continued float}
\label{dr:s:ist:som}
\end{figure}

\begin{figure}
\centering
\subfloat[test]{\includegraphics[width=3cm]{image5}}\quad
\subfloat[test]{\includegraphics[width=3cm]{image6}}
\caption{Another independent figure with subfigures}
\label{dr:s:ist:win}
\end{figure}

\end{document}

enter image description here

Now, the subfigures are correctly numbered, but figures are not. The definitive solution is to switch to the subcaption package (you can even use again the H specifier). In the following example I used \subcaptionbox, but the package offers also a subfigure environment:

\documentclass[a4paper]{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{subcaption}

\begin{document}

\begin{figure}[H]
\centering
\subcaptionbox{test}{\includegraphics[width=3cm]{image1}}\quad
\subcaptionbox{test}{\includegraphics[width=3cm]{image2}}
\caption{First part of a continued float}
\end{figure}

\begin{figure}[H]
\centering
\ContinuedFloat 
\subcaptionbox{test}{\includegraphics[width=3cm]{image3}}\quad
\subcaptionbox{test}{\includegraphics[width=3cm]{image4}}
\caption{Second part of the continued float}
\label{dr:s:ist:som}
\end{figure}

\begin{figure}[H]
\centering
\subcaptionbox{test}{\includegraphics[width=3cm]{image5}}\quad
\subcaptionbox{test}{\includegraphics[width=3cm]{image6}}
\caption{Another independent figure with subfigures}
\label{dr:s:ist:win}
\end{figure}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.