6

I have found several questions on TeX.SE and elsewhere about making figure captions span multiple pages (e.g., How do I make figure captions span multiple pages?). I gather that the caption package puts the caption in unbreakable boxes.

Some answers recommend the use of the capt-of package. capt-of seems to work fine, but breaks caption instances. So it seems that using capt-of to enable long figure captions would require me to switch every single caption in my paper to capt-of, which is a burden and seems to eliminate the benefits of floating figures.

Here's a MWE (also on Overleaf) with a figure with short caption and a figure with a long captionof. I would like to be able to have both \usepackage{capt-of} and \usepackage[font={small,sf}, singlelinecheck=false]{caption} enabled, and still have my long caption span multiple pages.

\documentclass{article}

% I can't have both caption and capt-of enabled.

% Caption alone doesn't let long captions span multiple pages.    
\usepackage[font={small,sf}, singlelinecheck=false]{caption}

% Capt-of alone would require me to reformat many figures.
\usepackage{capt-of}

% But enabling both breaks capt-of's ability to span captions across pages.

\usepackage{lipsum}

\begin{document} 

\lipsum[1]

% I have many figures that are formatted like this.
\begin{figure}[h!]
   \centering
   \rule{0.3\textwidth}{0.3\textheight}
\caption[Short caption]{\lipsum[1]}
\end{figure}

\lipsum[1-10]

% This seems to be the best way to get long captions to span multiple pages, while being styled like the above figure.
\begin{centering}
\sffamily
   \rule{0.5\textwidth}{0.75\textheight}
\captionof{figure}[short caption]{\lipsum[1-4]}
   \label{figure}
\end{centering}

\end{document}

Alternatively, some way to easily allow captions to span pages without having to re-format would be great.

Mr. W.
  • 211
  • The caption package also defines \captionof{...}{...}, so you don't need capt-of for that when you already load caption. And please add MWEs to the question rather than Overleaf. – Torbjørn T. Nov 04 '17 at 22:02
  • But caption alone doesn't allow captions to span multiple pages. I'll add the MWE now. – Mr. W. Nov 04 '17 at 22:03
  • 2
    latex floats are boxes and can never span multiple pages. – David Carlisle Nov 04 '17 at 22:03
  • @DavidCarlisle That's why I am willing to instead use non-floating captionof for my figures with very long captions. But if I use that alone, my caption formatting (small, sans-serif) is lost. – Mr. W. Nov 04 '17 at 22:06
  • Ah, right, sorry for the misunderstanding. (By the way, only you who owns the post is notified of all comments, if you want to notify other commenters, you need to write an at-sign followed by the username, e.g. @DavidCarlisle. Tab-completion of usernames is available.) – Torbjørn T. Nov 04 '17 at 22:08
  • 1
    unrelated but \begin{figure}[h!] is usually wrong, latex will warn and change it to [!ht] but [htp] would be better. – David Carlisle Nov 04 '17 at 22:30
  • While splitting works with the original caption command it imho won't work with the caption command from the caption package: it puts the caption inside a box. If you really want such long captions you will have to define your own command. – Ulrike Fischer Nov 04 '17 at 23:05
  • I would also be happy if there was a styling workaround to just use capt-of, and find a way to make all of my preexisting captions small and sans-serif. – Mr. W. Nov 04 '17 at 23:07
  • Scratching my head here. A caption longer than a page? Just make a section/subsection out of it. The caption would be short: \caption{What i was writing about for the last three pages}. – Johannes_B Nov 05 '17 at 06:29
  • @Johannes_B: It shouldn't be too hard to imagine. I'm writing a dissertation with strict formatting guidelines (i.e., huge margins), have a figure with many subplots that I'd like to be big and readable, and would like a detailed caption. But given the difficulty of getting this done, I do think I'm just going to adjust my caption length. – Mr. W. Nov 05 '17 at 17:21

2 Answers2

4

You don't need the capt-of package which is just one line and the same definition is in caption however caption boxes the caption text so if you want it to break you need to unbox it:

\documentclass{article}

% I can't have both caption and capt-of enabled.

% Caption alone doesn't let long captions span multiple pages.    
\usepackage[font={small,sf}, singlelinecheck=false]{caption}


\usepackage{lipsum}

\begin{document} 

\lipsum[1]

% I have many figures that are formatted like this.
\begin{figure}[h!]
   \centering
   \rule{0.3\textwidth}{0.3\textheight}
\caption[Short caption]{\lipsum[1]}
\end{figure}

\lipsum[1-10]

% This seems to be the best way to get long captions to span multiple pages, while being styled like the above figure.
\begin{center}

   \rule{0.5\textwidth}{0.75\textheight}

\bigskip
\setbox0\vbox{\makeatletter
\let\caption@rule\relax
\captionof{figure}[short caption]{\lipsum[1-4]}
\global\skip1\lastskip\unskip
\global\setbox1\lastbox
}
\unvbox0
\setbox0\hbox{\unhbox1\unskip\unskip\unpenalty
\global\setbox1\lastbox}
\unvbox1
\vskip\skip1



\end{center}

\end{document}
David Carlisle
  • 757,742
  • But your second caption now does not span multiple pages. You need to have \usepackage{capt-of} for that. – Mr. W. Nov 04 '17 at 22:31
  • @WillAdler capt-of package is is exactly one line of code and doesn't have anything that isn't already in the caption package? I'll see if I can re-create what you describe... – David Carlisle Nov 04 '17 at 22:33
  • 1
    @WillAdler updated answer with breaking caption – David Carlisle Nov 04 '17 at 23:26
  • Weirdly, any of \usepackage{xcolor}, \usepackage{color}and \usepackage[colorlinks = true]{hyperef} seem to break this solution. But I'll accept anyway! Thanks. – Mr. W. Nov 05 '17 at 17:19
  • It's not clear to me why this hack is needed. As far as I can see \captionsetup{rule=false,parbox=none}\captionof{figure}[...]{...} is sufficient. –  Nov 27 '19 at 20:10
1

By default the caption package puts the caption content inside a \parbox since this is needed for supporting some caption package options (margins etc.). But this can be changed with \captionsetup{parbox=...}, for example:

\documentclass{article}

\usepackage[font={small,sf}, singlelinecheck=false]{caption}
\usepackage{lipsum}

\begin{document} 

\lipsum[1]

% I have many figures that are formatted like this.
\begin{figure}[h!]
   \centering
   \rule{0.3\textwidth}{0.3\textheight}
\caption[Short caption]{\lipsum[1]}
\end{figure}

\lipsum[1-10]

% This seems to be the best way to get long captions to span multiple pages, while being styled like the above figure.
\begin{centering}
\sffamily
   \rule{0.5\textwidth}{0.75\textheight}
\captionsetup{parbox=none}% don't put this caption into a \parbox
\captionof{figure}[short caption]{\lipsum[1-4]}
   \label{figure}
\end{centering}

\end{document}