2

I am trying define different styles for nested tcolorboxes as in the following example. However the outer style doesn't seem to apply. Furthermore in my example "Alice" appears in the inner box and not in the outer one. The borderline setting doesn't apply too etc. What did I wrong?

\documentclass{article}

\usepackage{geometry}

\usepackage[most]{tcolorbox}
\definecolor{outer}{named}{blue}
\definecolor{inner}{named}{red}

\newtcolorbox{email}[1]{%
  every box/.style={
    colback=white,
    boxrule=0pt,
    coltitle=black,
    fontupper=\small\sffamily,
    fonttitle=\small\sffamily,
    title=\parbox{\linewidth}{#1\par},
  }, 
  every box on layer 1/.style={
    reset,
    every box,
    grow to right by=-1ex,
    grow to left by=-1ex,
    borderline west={3pt}{0pt}{outer!80},
    colframe=outer!60,
    colbacktitle=outer!15
  },
  every box on layer 2/.style={
    reset,
    every box,
    grow to right by=0mm,
    grow to left by=-1ex,
    borderline west={2pt}{0pt}{inner!80},
    colframe=inner!60,
    colbacktitle=inner!15,
  },
}

\usepackage{lipsum}

\begin{document}

\begin{email}{Alice}
\lipsum[1]
\begin{email}{Bob}
\lipsum[2]
\end{email}
\lipsum[3]
\begin{email}{Bob}
\lipsum[4]
\end{email}
\lipsum[5]
\end{email}

\end{document}

Output:enter image description here

2

This is not an answer but a long command. I don't know why it happens but if you declare all every box ... into an external tcbset declaration, your settings work. It seems that every box declarations doesn't work inside a \newtcolorbox:

\documentclass{article}

\usepackage{geometry}

\usepackage[most]{tcolorbox}
\definecolor{outer}{named}{blue}
\definecolor{inner}{named}{red}

\tcbset{
  every box/.style={
    colback=white,
    boxrule=0pt,
    coltitle=black,
    fontupper=\small\sffamily,
    fonttitle=\small\sffamily,
  }, 
  every box on layer 1/.style={
    reset,
    every box,
    grow to right by=-1ex,
    grow to left by=-1ex,
    borderline west={3pt}{0pt}{outer!80},
    colframe=outer!60,
    colbacktitle=outer!15
  },
  every box on layer 2/.style={
    reset,
    every box,
    grow to right by=0mm,
    grow to left by=-1ex,
    borderline west={2pt}{0pt}{inner!80},
    colframe=inner!60,
    colbacktitle=inner!15,
  },
}

\newtcolorbox{email}[1]{%
    title=\parbox{\linewidth}{#1\par},
}

\usepackage{lipsum}

\begin{document}

\begin{email}{Alice}
\lipsum[1]
    \begin{email}{Bob}
    \lipsum[2]
    \end{email}
\lipsum[3]
    \begin{email}{Bob}
    \lipsum[4]
    \end{email}
\lipsum[5]
\end{email}

\end{document}

enter image description here

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.