3

When a page break occurs in a nested tcolorbox the nested tcolorbox will be placed onto a new page. One way I could get round this behaviour is to create two separate boxes, one after the other, with the second one recreating the style of the nested box.

At the moment I haven't managed an exact match but there is an interior style setting that could be used to apply a more advanced style to the background colour that replicates the white border between the blue outer border and the grey background but I am not experienced enough to know if that is even possible.

Does anyone have any idea how the style could be replicated?

Nested box style

\documentclass{article}

\usepackage[breakable,skins]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{OuterBoxOne}{%
    enhanced,
    colback=white,
    colframe=blue,
}%
\newtcolorbox{InnerBoxOne}{%
    enhanced,
    colback=gray,
    colframe=white,
}%
\newtcolorbox{OuterBoxTwo}{%
    enhanced,
    colback=white,
    colframe=blue,
    bottomrule=0mm,
    sharp corners=south,
}%
\newtcolorbox{InnerBoxTwo}{%
    breakable,
    enhanced,
    colback=gray,
    colframe=blue,
    before=\vspace{-5pt},
    sharp corners=north,
    toprule=0cm,
}%

\begin{document}
    \begin{OuterBoxOne}
        \lipsum[1]
        \begin{InnerBoxOne}
            \lipsum[1]          
        \end{InnerBoxOne}       
    \end{OuterBoxOne}  
    \pagebreak
    \begin{OuterBoxTwo}
        \lipsum[1]               
    \end{OuterBoxTwo}  
    \begin{InnerBoxTwo}
        \lipsum[1]          
    \end{InnerBoxTwo}
\end{document}
1
  • 1
    Tcolorboxes with lower are also breakable, so I think it should be easier to use a regular tocolrbox with a lowerpart simulating a nested tcolorbox than using nested colorboxes.
    – Ignasi
    Commented Feb 22, 2017 at 10:11

1 Answer 1

1

It turns out I needed to use the more powerful interior code setting that allowed me to use pgf code which didn't restrict it to a specific style. This allowed me to draw a rounded corner rectangle which simulates the inner nested box style. I then needed to create three different styles for the first, middle and last sections of a broken box.

Compare nested boxes

The code below could be improved further but it works for me.

\documentclass{article}

\usepackage[breakable,skins]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{OuterBoxOne}{%
    enhanced,
    colback=white,
    colframe=blue,
}%
\newtcolorbox{InnerBoxOne}{%
    enhanced,
    colback=gray,
    colframe=white,
}%

\newtcolorbox{OuterBoxTwo}{%
    enhanced,
    colback=white,
    colframe=blue,
    bottomrule=0mm,
    sharp corners=south,
}%

\newtcolorbox{InnerBoxTwo}{%
    breakable,
    enhanced,    
    colback=gray,
    colframe=blue,
    before=\vspace{-5pt},
    sharp corners=north,
    toprule=0cm,
    left=25pt,
    right=25pt,
    bottom=10pt,
    overlay first={
        interior code={
            \path[fill=white] ([yshift=0.1cm]interior.north west) rectangle ([yshift=-0.1cm]interior.south east);
            \path[fill=gray] ([xshift=11.55cm,yshift=-1cm]interior.north west) rectangle ([xshift=-11.55cm]interior.south east);
            \path[fill=gray,rounded corners=5pt] ([xshift=11.55cm]interior.north west) rectangle ([xshift=-11.55cm,yshift=5pt]interior.south east);
        },
    },
    overlay middle={
        interior code={
            \path[fill=white] ([yshift=0.1cm]interior.north west) rectangle ([yshift=-0.1cm]interior.south east);
            \path[fill=gray] ([xshift=11.55cm]interior.north west) rectangle ([xshift=-11.55cm]interior.south east);
        }
    },
    overlay last={
        interior code={
            \path[fill=white] ([yshift=0.1cm]interior.north west) rectangle (interior.south east);
            \path[fill=gray] ([xshift=11.55cm]interior.north west) rectangle ([xshift=-11.55cm,yshift=1cm]interior.south east);
            \path[fill=gray,rounded corners=5pt] ([xshift=11.55cm]interior.north west) rectangle ([xshift=-11.55cm,yshift=5pt]interior.south east);
        }
    },
    interior code={
        \path[fill=white] ([yshift=0.1cm]interior.north west) rectangle (interior.south east);
        \path[fill=gray,rounded corners=5pt] ([xshift=11.55cm]interior.north west) rectangle ([xshift=-11.55cm,yshift=5pt]interior.south east);
    }
}%

\begin{document}
    \begin{OuterBoxOne}
        \lipsum[1]
        \begin{InnerBoxOne}
            \lipsum[1]          
        \end{InnerBoxOne}       
    \end{OuterBoxOne}  
    \pagebreak
    \begin{OuterBoxTwo}
        \lipsum[1]               
    \end{OuterBoxTwo}  
    \begin{InnerBoxTwo}
        \lipsum[1]   
    \end{InnerBoxTwo}
\end{document}

You must log in to answer this question.

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