4

I am following this question in Split subfigures over multiple pages

It works well. However, when I want to add in one more subfigure as (c) in first page, it not working well.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

    \begin{document}



\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 1}
        \label{fig:arm1}
    \end{subfigure}
%
    \begin{subfigure}[b]{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 2}
        \label{fig:arm2}
    \end{subfigure}
    \caption{$Q^{*}$ values for different arms}
%
    \begin{subfigure}[b]{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 3}
        \label{fig:arm2}
    \end{subfigure}
    \caption{$Q^{*}$ values for different arms}

\end{figure}%

\begin{figure}[htb]\ContinuedFloat
    \centering
    \begin{subfigure}[b]{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 4}
        \label{fig:arm3}
    \end{subfigure}
%
    \begin{subfigure}[b]{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 5}
        \label{fig:arm4}
    \end{subfigure}
    \caption{$Q^{*}$ values for different arms (cont.)}
    \label{fig:arms}
\end{figure}


    \end{document}

Not sure what is the problem by adding:

\begin{subfigure}[b]{0.6\textwidth}
    \includegraphics[width=\textwidth]{example-image}
    \subcaption{$Q^{*}$ values for arm 3}
    \label{fig:arm2}
\end{subfigure}
\caption{$Q^{*}$ values for different arms}

enter image description here

enter image description here

aan
  • 2,663

3 Answers3

3

This happen because you have two captions in the first (part of the) figure.

Command \caption[<optional short text>]{<long caption text>} do (simplified explained) the following:

  1. insert <long caption text> as caption text into figure (or table) float environment and <optional short text> to list of figures or tables
  2. increment caption number
  3. by second action reset eventual sub-caption numbering

The second action can be prevent with command \ContinuedFloat.

In your case aforementioned means, that in the second part of figure is not increment the last caption number nor (consequently) reset sub-caption number. Since in the first part of figure you have two captions, \ContinuedFloat in the second part of figure prevent increment of caption number of the second caption in the first part of figure and with this enable continuation of sub-captions numbering in the second part of figure from it.

It is not clear (at least to me), why you have two caption in the first part of figure. If having two caption is intentional, but you like to have the same number of following caption, than insert \ContinuedFloat after the first caption; if you left it accidentally in your code, than simple remove it.

In the second case you will obtain the following result:

enter image description here

Edit: Above image is produced by the following MWE:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

    \begin{document}
\begin{figure}[hb!]
    \centering
    \begin{subfigure}{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 1}
        \label{fig:arm1}
    \end{subfigure}

    \begin{subfigure}{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 2}
        \label{fig:arm2}
    \end{subfigure}

    \begin{subfigure}{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 3}
        \label{fig:arm2}
    \end{subfigure}
    \caption{$Q^{*}$ values for different arms}
\end{figure}%
\begin{figure}[ht]\ContinuedFloat
    \centering
    \begin{subfigure}{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 4}
        \label{fig:arm3}
    \end{subfigure}

    \begin{subfigure}{0.6\textwidth}
        \includegraphics[width=\textwidth]{example-image}
        \subcaption{$Q^{*}$ values for arm 5}
        \label{fig:arm4}
    \end{subfigure}
    \caption{$Q^{*}$ values for different arms (cont.)}
    \label{fig:arms}
\end{figure}
    \end{document}
Zarko
  • 296,517
  • thanks. It is my mistake having two caption, i am too tired and didnt see this. Thanks. It worked well. I want to ask one question. Usually we wrote Figure caption .....(cont.) at the second caption or first caption? – aan Jan 01 '20 at 10:10
  • thanks. Can I know what is there options of the alignment of subfigure (b in \begin{subfigure}[b]{0.6\textwidth}) beside b, t? Is there a list to check all the options? – aan Jan 01 '20 at 11:49
  • @ann, do you like to have three sub-figures parallel? In question you ask why sub-figures are not numbered in sequence ... – Zarko Jan 01 '20 at 12:47
  • I want the figure appear to be like yours, in vertical line. But I am curious what the b meaning in \begin{subfigure}[b]{0.6\textwidth}). – aan Jan 01 '20 at 12:50
  • @aan, [b] is positioning options for sub-figure. They are important when images are in parallel. In such case with option [b] are aligned at of images. With [t] option are aligned at the their top. In your case you can omit positioning options since sub-images are in vertical sequence, see edited answer – Zarko Jan 01 '20 at 14:11
  • 1
    @aan, any news? If answer solve your problem, you can accept it :-) – Zarko Jan 02 '20 at 03:16
0

\ContinuedFloat from subfig package does it.

It sometimes occurs, especially when using sub-floats, that a single figure needs to be continued across pages. The \ContinuedFloat command is placed at the beginning of the floating environment or after changing @captype inside the floating environment to make the next figure, table or other floating \caption a continuation of the last float \caption of the same type. It does this by saving the sub-float numbering internally and keeping the float numbering from advancing.


Update:

The MWE is basically:

\begin{figure}
\subfloat[][]{A}
\subfloat[][]{B}
\caption{Fig. 1}
\end{figure}
\begin{figure}
\ContinuedFloat
\subfloat[][]{C}
\subfloat[][]{D}
\caption{Fig. 2}
\end{figure}

The production code looks like this, there is a lot of fiddling which I do not remember why it was done. It includes some fiddling with the figure counter to keep the same figure number.

\begin{figure}[pt]
\let\tabsepbakup\tabcolsep
\renewcommand{\tabcolsep}{0.1ex}
\begin{tabular}{rl}
\multicolumn{2}{r}{%
\sidebysidecaption{0.75\linewidth}{0.23\linewidth}{%
\subfloat[R1: The first section]{\begin{tabular}[b]{c}
\includegraphics[width=0.495\linewidth]{R1_scan.png}
\\
\includegraphics[width=0.495\linewidth]{scale.png}
\end{tabular}
\label{fig:km-4-a}}
%\hspace*{0.1ex}
\setcounter{subfigure}{3}%
\subfloat[R2: The first section]{\begin{tabular}[b]{c}
\includegraphics[width=0.495\linewidth]{R2_scan.png}
\\
\includegraphics[width=0.495\linewidth]{scale.png}
\end{tabular}
\label{fig:km-4-d}}
}{% \vspace*{1em}
  \hspace*{\tabcolsep}\hspace*{0.1\linewidth}\vspace*{0pt}%
  \hfill%
  \caption[Regions of interest as sections and as reconstructions]{First scan of R1, R2
  immunostaining in combination with front views of the 3D models
  coloured for shape diameter and connectivity visualisation. Scale
  bar for all images~$=$ \SI{200}{\micro\meter}. \emph{(Continued on the next page, full caption on page~\pageref{fig:km-4-caption}.)}}%
\label{fig:km-4}
}}
%
\setcounter{subfigure}{2} \\

\setcounter{subfigure}{1}%
\subfloat[R1: The shape diameter]{\includegraphics[width=0.495\linewidth]{r1_red_frame_br_.png}\label{fig:km-4-b}} &
\setcounter{subfigure}{4}%
\subfloat[R2: The shape diameter]{\includegraphics[width=0.495\linewidth]{r2_red-from_blue_y_bg.png}\label{fig:km-4-e}}
\\
\setcounter{subfigure}{2}%
\subfloat[R1: The connectivity study]{\includegraphics[width=0.495\linewidth]{r1_overview_frame_y_.png}\label{fig:km-4-c}} &
\setcounter{subfigure}{5}%
\subfloat[R2: The connectivity study]{\includegraphics[width=0.495\linewidth]{r2_overview_frame_y-border.png}\label{fig:km-4-f}} \\
\end{tabular}
\renewcommand{\tabcolsep}{\tabsepbakup}
%%% need a hack for contcaption
%%% increment the figure counter so it might be decremented again
\stepcounter{figure}
\end{figure}
\begin{figure}[tp]
\ContinuedFloat
%% <-------------------- that's the point
\let\tabsepbakup\tabcolsep
\renewcommand{\tabcolsep}{0.1ex}
\begin{tabular}{rl}
\multicolumn{2}{r}{%
\sidebysidecaption{0.24\linewidth}{0.75\linewidth}{%
  \contcaption{\emph{(Continued from previous page.)} First scan of R3, R4
  immunostaining and front views of the 3D models
  coloured for shape diameter and connectivity visualisation. % Scale
  % bar for all images~$=$ \SI{200}{\micro\meter}.
  \emph{(Full caption on the next page.)}}
}{%
\hspace*{0pt}%
\vspace*{0pt}%
\hspace*{-0.5\linewidth}%
\hfill%
\subfloat[R3: The first section]{%
\renewcommand{\tabcolsep}{0ex}
\begin{tabular}[b]{c}
\includegraphics[height=0.495\linewidth]{R3_scan.png}
\\
\includegraphics[width=0.495\linewidth]{scale.png}\label{fig:km-4-g}
\end{tabular}%
\renewcommand{\tabcolsep}{0.1ex}
}%
\setcounter{subfigure}{9}%
\subfloat[R4: The first section]{%
\renewcommand{\tabcolsep}{0ex}
\begin{tabular}[b]{c}
\includegraphics[height=0.495\linewidth]{R4_scan.png}
\\
\includegraphics[width=0.495\linewidth]{scale.png}\label{fig:km-4-j}
\end{tabular}%
\renewcommand{\tabcolsep}{0.1ex}
}%
}\setcounter{subfigure}{7}}
\\
\subfloat[R3: The shape diameter]{\includegraphics[width=0.495\linewidth]{r3_red_frame_.png}\label{fig:km-4-h}} &
\setcounter{subfigure}{10}%
\subfloat[R4: The shape diameter]{\includegraphics[width=0.495\linewidth]{r4_red_frame_.png}\label{fig:km-4-i}}
\\
\setcounter{subfigure}{8}%
\subfloat[R3: The connectivity study]{\includegraphics[width=0.495\linewidth]{r3_blue_.png}\label{fig:km-4-k}}
 &
\setcounter{subfigure}{11}%
\subfloat[R4: The connectivity study]{\includegraphics[width=0.495\linewidth]{r4_overview_front_.png}\label{fig:km-4-l}}
\\
\end{tabular}
\renewcommand{\tabcolsep}{\tabsepbakup}
\end{figure}
\begin{figure}[th]
\contcaption{\emph{(On two previous pages)} First scan of R1 (a), R2 (d), R3 (g) and R4 (j)
 immunostaining in combination with front views of the 3D models
 coloured for shape diameter (b, e, h, k) and connectivity visualisation
 (c, f, i, l). In (b), (e), (h), and (k) a shape diameter below \SI{20}{\micro\meter} is
 depicted in red and above \SI{40}{\micro\meter} in green. A transition from red to
 green occurs in microvessels of shape diameters from \SI{20}{\micro\meter} to \SI{40}{\micro\meter} with middle at \SI{23.5}{\micro\meter}. 
 In (c), (i), and (l) the largest continuous microvessel network is depicted in light blue and all smaller networks are green. In (f)
 there are several large networks, all coloured in blue. Small
 structures sized between \SI{50}{\micro\meter} and \SI{12.5}{\micro\meter} are red in (c), (f), (i), and
 (l), and all structures with a diameter less than \SI{12.5}{\micro\meter} in any
 dimension are omitted. (b, c) R1; (e, f) R2; (h, i) R3; (k, l) R4. Scale
 bar for all images: \SI{200}{\micro\meter}.}
\label{fig:km-4-caption}
\end{figure}

The \sidebysidecaption macro is not really related, but for the sake of completeness:

\newcommand{\sidebysidecaption}[4]{%
\RaggedRight%
% https://tex.stackexchange.com/questions/29143/caption-on-the-side-of-a-figure
  \begin{minipage}[t]{#1}
    \vspace*{0pt}
    #3
  \end{minipage}
  % \mbox{}\\[-\baselineskip]
  \hfill%
  \begin{minipage}[t]{#2}
    \vspace*{0pt}
    #4
\end{minipage}%
% \mbox{}\\[-\baselineskip]
}

The production code above requires:

\usepackage[font=footnotesize,labelfont=sf,textfont=sf]{subfig}

\usepackage[footnotes]{ragged2e} % for RaggedRight
%% it is used with microtype
%% http://tex.stackexchange.com/questions/134303/does-combining-microtype-with-ragged-right-make-any-sense
\setlength\RaggedRightRightskip{1pt plus 2em minus 1pt} % default is: 0pt plus 2em

The final result looks like this:

example screenshot

  • can you explain more or show MWE? I could not understand your sentences – aan Jan 01 '20 at 02:20
  • That was a quote from the documentation of subfig, but I have added an MWE and a production example now. Could a downvoter explain what was wrong? – Oleg Lobachev Jan 01 '20 at 02:30
  • thanks. However, if I want to use back my original MWE, what is the wrong with my code? – aan Jan 01 '20 at 02:34
  • because I just want to have a single line centre figure (a), (b), (c) in page 1 and then (c) and (d) in second page – aan Jan 01 '20 at 02:35
  • I looks like you use old subfigure code. I suggest upgrading to subfig. Then you just say \ContinuedFloat in the second figure. – Oleg Lobachev Jan 01 '20 at 02:37
  • yes, I just want to use subfigure original code. But if I put \ContinuedFloat in second figure, it turn out to be 3 pages – aan Jan 01 '20 at 02:41
  • @OlegLobachev Aan does not use old subfigure code, he/she uses recent subcaption code. –  Jan 02 '20 at 10:21
0

I support the "Mr. Zarko" and especially for Elsevier format && And it also supports the other format &&&&&& If you are working on overleaf then it's very helpful for me.

Extra Package require:-#### 
%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{caption}
\usepackage{subcaption}
%%%%%%%%%%%%%%%%%%%%%%%%

Summarize the "Mr. Zarko" answer

\begin{figure}[h!]
    \centering
     \begin{subfigure}{0.6\textwidth}
     \centering
     .
     .
     \end{subfigure}
     \hfill
     \begin{subfigure}{0.6\textwidth}
     \centering
     .
     .
     \end{subfigure}
     .
     .
\end{figure}
\begin{figure}[ht]\ContinuedFloat
    \centering
     \begin{subfigure}{0.6\textwidth}
     \centering
     .
     .
     \end{subfigure}
     \hfill
     \begin{subfigure}{0.6\textwidth}
     \centering
     .
     .
     \end{subfigure}
     .
     .
\end{figure}

Note:

    1. indentation is important (for example: - \hfill and \end{figure} are in one line ).
Zarko
  • 296,517
  • 1
    Welcome to TeX.SE! If you like to have two images in one row, than you also need to reduce width of subfig to equal or les than 0.5\textwidth. – Zarko Jan 17 '21 at 13:40