2

This is follow-up question of my previous question tcolorbox: It is possible to put breakable boxes behind each other (overlap)?.

My question: how can I simulate various defined breakable boxes inside a breakable box by overlapping, so they seem to be inside each other? The defined boxes are for example

\newtcolorbox{}

Example would be enter image description here

2
  • Do you know the size of each part in broken boxes?
    – Ignasi
    Commented Apr 17, 2018 at 15:20
  • @Ignasi it varies depending on the content (user input), but it is measurable i think Commented Apr 17, 2018 at 19:07

1 Answer 1

3

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}

enter image description here

8
  • wow thanks!! :D how do you know this stuff haha? Commented Apr 18, 2018 at 8:38
  • but I already predefined the inner boxes (the black, red, brown, blue boxes in your answer) in a separate \newtcolorbox where I defined frame color, background color etc, so I would like to 'instantiate' them only and without redefining them. Is it possible too? Commented Apr 18, 2018 at 9:19
  • @FacebFaceb You have to adapt this solution to your taste. If you read the code (I hope you do it) you'll see that outer box is fixed for all of them but all other parmeters can be adapted. In any case you have to decide which box if the first and declare it as topbox, which are in the middle and declare as middlebox and which one is the last one and declare as bottombox.
    – Ignasi
    Commented Apr 18, 2018 at 9:25
  • @FacebFaceb As I've already explained you, what you want (breakable neste d boxes) is NOT possible, at least with this version of tcolorbox. Therefore these codes are partial solutions that can I think solve your question. Now it's your time to decide if you want to use or not and adapt to the real situation.
    – Ignasi
    Commented Apr 18, 2018 at 9:30
  • I will try, thanks anyway! Is it possible to reuse parts of your code by \newcommand, if some parts are similar to each other? Commented Apr 18, 2018 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .