I am currently using tcolorbox to create a rounded corner grey box within a rounded corner bordered box:
\documentclass{article}
\usepackage[breakable,skins]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{OuterBox}[1][]{%
breakable,
enhanced,
colback=white,
colframe=blue,
#1}%
\newtcolorbox{InnerBox}[1][]{%
enforce breakable,
enhanced,
colback=gray,
colframe=white,
#1}%
\begin{document}
\begin{OuterBox}
Just a line of text
\begin{InnerBox}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\lipsum[1]
\end{InnerBox}
\end{OuterBox}
\end{document}
In the above example the nested tcolorbox
is started on the next page instead of continuing straight after the contents of the outer box which is rather messy. In more complex documents it becomes very messy:
Preventing the inner box from being breakable fixes those graphical glitches and is the reason why the documentation cautions against its use:
In the unlikely case you really want to have the nested box to be
breakable, use/tcb/enforce breakable
for the nested box. But, a
breakable box inside a breakable box will usually give a mess.
This is also a limitation of mdframed
as it's documentation states:
A nested mdframed environment can’t be splitted.
Is there an alternative package that does support this use?
Best Answer
I propose a partial solution. The main shortcoming is its dependence on later changes made in the
.tex
file.The idea is to introduce a command that ends the current inner box and starts a new one. If a breaking is needed, the command is inserted in the text and the desired split is achieved. Without forcing the breaking of the inner box (not needed). In the code below the command is
\splitbox
. Moreover, starting with the default values of the inner box, TikZ is used to construct sharp corners at the bottom of the current page and at the top of the next one for the split box.Note that due to
\lipsum[n]
behavior with respect to the neighboring paragraphs, I inserted normal text in the inner box (as in a normal text file).