Following with the idea proposed in tcolorbox: It is possible to put breakable boxes behind each other (overlap)? this code proposes to declare three kind of boxes: topbox
, middlebox
and bottombox
.
topbox
must the first in the desired series, it contains and draws the outer title
. After a topbox
you can place as much as middlebox
-es as you want and the series ends with a bottombox
which will close the false outer tcolorbox.
middlebox
draws outer lines and enlarges them to join previous topbox
and following bottombox
. It shows a wrong behaviour when the middle box is not broken and it's placed to the bottom of a page. I don't know how to solve it.
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{topbox}[2][]{
title=#2,
enhanced, breakable,
enlarge top initially by=1cm,
% enlarge bottom finally by=5mm,
enlarge left by=5mm,
enlarge right by=5mm,
width=\linewidth-10mm,
overlay unbroken and first={
\draw[green!70!black, line width=.5mm, rounded corners]
([xshift=-5mm]frame.south west)|-([yshift=1cm]frame.north)-|
([xshift=5mm]frame.south east);
\node[fill=green!70!black, minimum height=5mm,
minimum width=\linewidth, anchor=north] at ([yshift=1cm]frame.north)
(outertitle) {};
\node[text=white, anchor=west] at ([xshift=3mm]outertitle.west) {Outer title};
},
overlay middle and last={
\draw[green!70!black, line width=.5mm]
([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
},
#1
}
\newtcolorbox{middlebox}[2][]{
title=#2,
enhanced, breakable,
% enlarge top initially by=1cm,
% enlarge bottom finally by=5mm,
enlarge left by=5mm,
enlarge right by=5mm,
width=\linewidth-10mm,
overlay unbroken={
\draw[green!70!black, line width=.5mm]
([shift={(-5mm,5mm)}]frame.north west)--([shift={(-5mm,-5mm)}]frame.south west)
([shift={(5mm,5mm)}]frame.north east)--([shift={(5mm,-5mm)}]frame.south east);
},
overlay first={
\draw[green!70!black, line width=.5mm]
([shift={(-5mm,5mm)}]frame.north west)--([xshift=-5mm]frame.south west)
([shift={(5mm,5mm)}]frame.north east)--([xshift=5mm]frame.south east);
},
overlay middle={
\draw[green!70!black, line width=.5mm]
([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
},
overlay last={
\draw[green!70!black, line width=.5mm]
([xshift=-5mm]frame.north west)--([shift={(-5mm,-5mm)}]frame.south west)
([xshift=5mm]frame.north east)--([shift={(5mm,-5mm)}]frame.south east);
},
#1
}
\newtcolorbox{bottombox}[2][]{
title=#2,
enhanced, breakable,
% enlarge top initially by=1cm,
enlarge bottom finally by=5mm,
enlarge left by=5mm,
enlarge right by=5mm,
width=\linewidth-10mm,
overlay unbroken and last={
\draw[green!70!black, line width=.5mm, rounded corners]
([xshift=-5mm]frame.north west)|-([yshift=-5mm]frame.south)
-|([xshift=5mm]frame.north east);
},
overlay first={
\draw[green!70!black, line width=.5mm]
([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
},
overlay middle={
\draw[green!70!black, line width=.5mm, rounded corners]
([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
},
#1
}
\begin{document}
\lipsum[1]
\begin{topbox}{this is the title}
\lipsum[1-2]
\end{topbox}
\begin{middlebox}[colframe=red, colback=pink!10]{this is the title}
\lipsum[1-5]
\end{middlebox}
\begin{middlebox}[colframe=brown!70!black, colback=brown!10]{this is the title}
\lipsum[1-2]
\end{middlebox}
\begin{bottombox}[colframe=blue, colback=cyan!10]{this is the title}
\lipsum[1-3]
\end{bottombox}
\lipsum[1]
\end{document}