2

I have a box with a modified border style, but when I nest two of such boxes, the style of the inner one is not the one that I set. I know, from the doc and from other questions on this stackexchange, that nesting breakable boxes can create problem, but I don't remember having read anything about styles.

So my question: how can I nest boxes while preserving the style like if the inner one is not nested ?

An image with two boxes, the first one is displayed properly; the second one contains an other box inside, which does not have the correct stype.

\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\tcbset{
    enhanced,
    frame hidden,
    sharp corners,
    }

\newtcolorbox{sidebox}{
    borderline={1pt}{0pt}{gray!80!cyan},
    colback=gray!80!cyan!5,
}

\begin{document}
\begin{sidebox}
    \[A=B\]
\end{sidebox}

\begin{sidebox}
\begin{sidebox}
    \[A=B\]
\end{sidebox}
\end{sidebox}
\end{document}

Notice that, in this MWE, I nest the same kind of box (i.e. a sidebox in a sidebox), but in practice, it is not necessarily the case, and the box might have been created with \tcolorboxenvironment.

6

I suggest to read section 4.16 Layered Boxes and Every Box Settings in tcolorbox documentation where relation between layered styles are explained.

With your example, it seems that changing \tcbset by \tcbsetfoereverylayer works.

\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\tcbsetforeverylayer{
    enhanced,
    frame hidden,
    sharp corners,
    }

\newtcolorbox{sidebox}{
    borderline={1pt}{0pt}{gray!80!cyan},
    colback=gray!80!cyan!5,
}

\begin{document}
\begin{sidebox}
    \[A=B\]
\end{sidebox}

\begin{sidebox}
\begin{sidebox}
    \[A=B\]
\end{sidebox}
\end{sidebox}
\end{document}

enter image description here

2
  • 1
    Works like a charm. Do you know the rationale for why options are not preserved for every layers by default?
    – Bromind
    Sep 3 '20 at 7:39
  • It is discussed in section 4.16 of the documentation of tcolorbox, but no rationale is provided as far as I can tell.
    – Clément
    Sep 9 at 4:06

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.