13

I'm using the KOMA scrreprt class. I have a large figure with 6 subfigures, and a lengthy (but necessary!) caption explaining the figure that doesn't fit on the same page. I'm trying to use the \captionof command in a centering environment to produce a caption that will automatically wrap to the next page; something like

\begin{center}
  \begin{figure} [h!]
    \subfigure[ ]{ \includegraphics{picture1.pdf} }
    \subfigure[ ]{ \includegraphics{picture2.pdf} }
    ...
    \subfigure[ ]{ \includegraphics{picture3.pdf} }
  \end{figure}
  \captionof{figure}[Short caption]{Long caption explaining the whole figure}
\end{center}

The figure is getting repositioned to the end of the section (even with the h! float specifier), and the caption ends up dissociating from the figure so that they appear in completely different parts of the document. I assume this is because I am still using the figure environment? But I need this for subfigure to work. Using the H specifier from the float package helps - I get the caption and the figure on consecutive pages - but the caption still doesn't wrap the way I'd like, the figure is on its own page with no label, and the KOMA scrreprt class throws an error.

Is there either a) an alternative to subfigure that will handle labels in the same way, or b) a way to make \captionof play nicely with the figure float?


Edit:

Werner's answer below is excellent, but it has two small problems:

1) The figure itself now splits over two pages, so that the first two images are on a page with some other material. Is there a way to prevent this? (easily fixed with a \newpage command just above the figure)

2) Although the ToF entry is perfect, the reference numbering in the text is broken. I suspect that the figure is getting numbered as a table. Werner to the rescue again: \def\@currentlabel{\thefigure}\label{<label>} works with a slight quirk. I have assigned labels to each subfigure, and they all end up appearing the same in the compiled document, so subfigure specifiers – e.g. (a) – have to be added manually. The label redefinition can be added to the after page argument instead.

  • 1
    So you want the figure to cover the entire page, with the caption at the bottom, but allow it to flow to the subsequent page, correct? – Werner Jul 15 '14 at 0:09
  • The follow is wrong in your code: (1) Wrapping a float (figure) inside another environment (center); (2) thinking that [!h] will force a float to stay put (see How to influence the position of float environments like figure and table in LaTeX?); – Werner Jul 15 '14 at 0:36
  • Thanks Werner. You are right about how I would like the figure to look - I want the caption to float onto the next page as necessary. The reason for wrapping the figure in the center environment is to allow the use of \captionof and associate it with the figure. I know it's not quite right! – charrison Jul 15 '14 at 12:36
8

Since this seems like an out-of-the-ordinary setting for a figure, it may require some manual fiddling. The following example sets a list-like environment containing the "figure", and it allows your caption to break across the page boundary.

enter image description here

\documentclass{scrartcl}
\usepackage{graphicx,lipsum,afterpage,subcaption}
\usepackage{enumitem}
\begin{document}

\lipsum[1-5]

\makeatletter
\afterpage{\begin{center}
    \def\@captype{figure}% Fake a figure environment
    \subcaptionbox{Sub1}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub2}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub3}{\includegraphics[width=.2\linewidth]{example-image-a}} \par\bigskip
    \subcaptionbox{Sub4}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub5}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub6}{\includegraphics[width=.2\linewidth]{example-image-a}}
  \end{center}
  \addcontentsline{lof}{figure}{\protect\numberline{\thefigure}A length figure}% LoF entry
  \settowidth{\@tempdima}{Figure~\thefigure: }%
  \begin{itemize}[labelindent=\parindent,labelwidth=\@tempdima,rightmargin=\parindent,leftmargin=\dimexpr\@tempdima+\parindent]
    \item[Figure~\thefigure:]
    \lipsum[6-10]
  \end{itemize}
}
\makeatother

\lipsum[6-12]

\end{document}

The sub-figures are set using subcaption using the regular interface inside a center environment. A faked figure is initiated by defining the caption type \@captype. Setting of the caption is inside a regular list itemize with appropriate width settings (to match your other figures).

A short LoF-entry is set manually via \addcontentsline{lof}{figure}{<short entry>}. This is displayed with the inclusion of \listoffigures.

All of the above is passed to \afterpage (supplied by afterpage) in order to provide a seemless transition from page-to-page. One may play around with the spacing following the "figure". For example, adding something like \addvspace{\textfloatsep}.

The page layout was added via \usepackage{showframe} in the preamble; removed in the above code.

  • Thank you very much for your effort Werner. For anyone else's benefit, I had to recode all of my figures that used subfigure to use subcaptionbox instead, and temporarily remove my includeonly commands to reset the aux files. I now have two other problems: 1) my large figure splits over two pages, so that the first two images are on a page with some other material. Is there a way to prevent this? And 2) the figure numbers in my references are messed up. The figure is 3.12; when I reference the subfigures it appears in the text as 3.2.2. Is it getting numbered as a table? – charrison Jul 15 '14 at 13:45
  • 1
    @charrison: Try adding \def\@currentlabel{\thefigure}\label{<label>} to your fake figure. This should restore the correct label. Note that my suggestion of using afterpage may be conditional on what is surrounding it at that stage of the document. Other floats used around it may cause your figure numbering to be wrong, specifically because you're not treating it as a regular (boxed) float. – Werner Jul 16 '14 at 6:18
4

This solution is based on three ideas:

  1. We use a center environment instead of a figure since the content of a figure is limited to one page only. (This idea was stolen from Werner.) We use \setcaptiontype{figure} (or \captionsetup{type=figure}) to make this environment known to the (sub)caption package as figure. BTW: Please don't use \def\@captype{figure} when using the caption package. When doing so this solution won't work correctly with hyperref, caption settings for figures would not apply etc.
  2. We use \afterpage to let this thing start on a page. (This idea was stolen from Werner, too.)
  3. We use \captionsetup{box=none,parbox=none} to avoid the usage of boxes when typesetting the caption since boxes would limit the caption to one page only. (Finally a idea from myself ;-))

Example code, shamelessly stolen from Werner and modified:

\documentclass{scrartcl}
\usepackage{graphicx,lipsum,afterpage,subcaption}
\begin{document}

\lipsum[1-5]

\afterpage{\begin{center}
    \setcaptiontype{figure}% Fake a figure environment
    \subcaptionbox{Sub1}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub2}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub3}{\includegraphics[width=.2\linewidth]{example-image-a}} \par\bigskip
    \subcaptionbox{Sub4}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub5}{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subcaptionbox{Sub6}{\includegraphics[width=.2\linewidth]{example-image-a}}
    \captionsetup{box=none,parbox=none}
    \caption[A length figure]{%
      \lipsum[6-10]}
  \end{center}
}

\lipsum[6-12]

\end{document}

There is no need to switch to the subcaption package since this solution works with the subfigure package, too:

\documentclass{scrartcl}
\usepackage{graphicx,lipsum,afterpage,caption,subfigure}
\begin{document}

\lipsum[1-5]

\afterpage{\begin{center}
    \setcaptiontype{figure}% Fake a figure environment
    \subfigure[Sub1]{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subfigure[Sub2]{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subfigure[Sub3]{\includegraphics[width=.2\linewidth]{example-image-a}} \par\bigskip
    \subfigure[Sub4]{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subfigure[Sub5]{\includegraphics[width=.2\linewidth]{example-image-a}} \qquad
    \subfigure[Sub6]{\includegraphics[width=.2\linewidth]{example-image-a}}
    \captionsetup{box=none,parbox=none}
    \caption[A length figure]{%
      \lipsum[6-10]}
  \end{center}
}

\lipsum[6-12]

\end{document}

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.