# How to get figure caption to span multiple pages, without having to switch everything to capt-of?

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.

• 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 4 '17 at 22:02
• But caption alone doesn't allow captions to span multiple pages. I'll add the MWE now. – Mr. W. Nov 4 '17 at 22:03
• latex floats are boxes and can never span multiple pages. – David Carlisle Nov 4 '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 4 '17 at 22:06
• unrelated but \begin{figure}[h!] is usually wrong, latex will warn and change it to [!ht] but [htp] would be better. – David Carlisle Nov 4 '17 at 22:30

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}

• But your second caption now does not span multiple pages. You need to have \usepackage{capt-of} for that. – Mr. W. Nov 4 '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 4 '17 at 22:33
• @WillAdler updated answer with breaking caption – David Carlisle Nov 4 '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 5 '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. – user2574 Nov 27 '19 at 20:10

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}