Tcolorbox:外部样式不起作用

Tcolorbox:外部样式不起作用

我正在尝试为嵌套的 tcolorboxes 定义不同的样式,如下例所示。但是外部样式似乎不适用。此外,在我的示例中,“Alice”出现在内部框中,而不是外部框中。边界线设置也不适用等等。我做错了什么?

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

输出:在此处输入图片描述

答案1

这不是一个答案,而是一个长命令。我不知道为什么会发生这种情况,但如果您将所有内容声明every box ...为外部tcbset声明,您的设置就会起作用。似乎every box声明在内部不起作用\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}

在此处输入图片描述

相关内容