# Nesting tcolorbox changes border style

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 ?

\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.

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}


• Works like a charm. Do you know the rationale for why options are not preserved for every layers by default? 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. Sep 9 at 4:06