In my document, I have tcolorbox
es containing large definitions that span from half a page to two pages. To reference these boxes in my main text, I would like to refer to them as I would for figures. For the smaller ones, I can embed them in a figure
environment like this:
\begin{figure}
\begin{tcolorbox}
\lipsum[1-3] % This normally contains some mathematical specifications.
\end{tcolorbox}
\caption{small definition.}
\end{figure}
However, for the bigger ones, I need to have a breakable tcolorbox
, and this doesn't work well inside a figure
environment. Let me show what I tried:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3] % Start the document with some text.
\begin{figure}
\begin{tcolorbox}[breakable]
\lipsum[1-8] % This normally contains some mathematical specifications.
\end{tcolorbox}
\caption{big definition.}
\end{figure}
\end{document}
See the image below to observe the weird result.
My question: Is it possible to add a caption below or above a breakable tcolorbox
, in the same style as in a figure
environment? A custom environment/caption numbering would be fine too. Preferably, the boxes that fit on one page should be floating. For the ones that span multiple pages, I don't think floats are appropriate anymore, so that is of less importance.
Note: I know captions for tcolorbox
es are often simulated by using the title
option. However, I would like to have a caption in the same style as a figure
/table
/…, that is above or below the box.
Best Answer
The
caption
package has the macro\captionof
that can be used for such cases to provide a float-like caption for non-floats. It should, however, placed inside a box, such as aminipage
.It uses the very same style as other captions and it will also take over the numbering of the floats. Therefore, you are able to mix real-float captions and non-float captions as you like.
So, you could do the following:
The last part of the output would then be something like:
I think, the macro is quite self-explanatory: The first argument takes the kind of float this non-float caption should imitate and the second argument takes the caption.