2

This question is a follow-up of various defined breakable boxes inside breakable box using overlapping.

How can I integrate the style on page 162 of the manual to the breakable boxes inside breakable boxes? It is more about the location, where to put the code, because whatever I tried the result is the same

  • 1
    Please show us what you tried in the form of a minimal working example. Also, CTAN don't like you linking to a specific mirror and doing so is fragile anyway. Better use the primary link and let the round robin sort a mirror out. – cfr Apr 21 '18 at 21:39
5
+50

I've modified topbox tcolorbox to use three parameters (one optional and two mandatory), the second mandatory parameter is the title for the outer box. This title. It doesn't work for long titles.

\documentclass{article}
\usepackage{varwidth}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{topbox}[3][]{enhanced,
    before skip=2mm,after skip=2mm,
    colback=black!5,colframe=black!50,boxrule=0.2mm,
    attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={frame code={
            \path[fill=tcbcolback!30!black]
            ([yshift=-1mm,xshift=-1mm]frame.north west)
            arc[start angle=0,end angle=180,radius=1mm]
            ([yshift=-1mm,xshift=1mm]frame.north east)
            arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
            middle color=tcbcolback!80!black]
            ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
            [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
            -- (frame.south east) -- (frame.south west)
            -- ([xshift=-1mm,yshift=-1mm]frame.north west)
            [sharp corners]-- cycle;
        },interior engine=empty,
    },
    fonttitle=\bfseries,
    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=9mm]frame.north)-|
        ([xshift=5mm]frame.south east);
        \coordinate (outernw) at ([shift={(-5mm,1cm)}]frame.north west);
        \node[fill=green!70!black, minimum height=5mm, 
        anchor=north west, text=white, rounded corners] at ([xshift=1cm]outernw) 
        (outertitle) {#3};
        \path[fill=green!30!black]
            ([yshift=-1mm,xshift=-1mm]outertitle.north west)
            arc[start angle=0,end angle=180,radius=1mm]
            ([yshift=-1mm,xshift=1mm]outertitle.north east)
            arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=green!60!black,right color=green!60!black,
            middle color=green!80!black]
            ([xshift=-2mm]outertitle.north west) -- ([xshift=2mm]outertitle.north east)
            [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]outertitle.north east)
            -- (outertitle.south east) -- (outertitle.south west)
            -- ([xshift=-1mm,yshift=-1mm]outertitle.north west)
            [sharp corners]-- cycle;
        \node[text=white] at (outertitle) {#3};

    },
    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}{Outer 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

Note Previous code has been updated for compatibility with tcolorbox v4.20. If you're using previous versions, rename colors with form tcbcol... to older form tcbcol@....

  • Amazing answer. Bottomline for dummies: boxed title style={etc. and try enhanced, you probably need it. – PatrickT Nov 29 '18 at 18:45
  • @PatrickT Thank you for the compliments. I'm sorry but I don't understand the second part of your comment. – Ignasi Nov 29 '18 at 18:52
  • you're welcome! I spent an hour trying to work out why I wasn't able to have \includegraphics inside option overlay= (with a node for positioning) until I realised, by reading your code, that I was missing option enhanced. :-) – PatrickT Nov 29 '18 at 18:56
  • @PatrickT you're right, I also forgot to add it. ;-) – Ignasi Nov 29 '18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.