The breakable boxes made by tcolorbox play nicely with figures that have been defined before the box but have not been typeset yet. Here's an example:
The three figures have been issued before the yellow box began, and have no problem appearing on the first page of the breakable box or the page after that.
My problem is that I have some figures that I want to appear later throughout a multi-page breakable box, so I want to issue them somewhere throughout a box. This does not work – any attempt to define figure inside a tcolorbox gives this error:
Not in outer par mode.
I tried to work around that by wrapping the figure into an \afterpage, to make sure it is processed outside of the tcolorbox context, but this didn't help at all.
Is there any way to insert a figure while a breakable tcolorbox is open so they are typeset at a controllable later point throught the box?
To put things into a minimal example: The questions is how to get something like this working:
\documentclass{article}
\usepackage{lipsum}
\usepackage[breakable]{tcolorbox}
\begin{document}
\begin{figure}
\centering\Huge
This is a figure.
\caption{A figure that will work}
\end{figure}
\begin{tcolorbox}[breakable]
\lipsum[1-20]
\begin{figure}
\centering\Huge
This is a figure.
\caption{A figure that will not work}
\end{figure}
\lipsum[21-30]
\end{tcolorbox}
\end{document}

begin{figure}, just\includeand\cptionof` for the captions. – yannisl Mar 03 '24 at 17:09\@deferlistwithout using the float environment. Get an insert from\@freelist, put the figure into the box register, the bit flags into the count register and the total height into the length register. OTOH, see https://tex.stackexchange.com/questions/689529/how-to-let-a-figure-appear-exactly-on-page-16 – John Kormylo Mar 03 '24 at 22:59\outputroutine which will do this background decoration with\box255. The floats (i.e.\inserts from TeX primitive point of view) will work in this case. – wipet Mar 04 '24 at 07:20\outputroutine level, if you want to have floats (i.e.\inserts) inside decorated text. – wipet Mar 04 '24 at 15:21