如何使用相同的样式更改不同 tcolorbox 中的标题

如何使用相同的样式更改不同 tcolorbox 中的标题

tcolorbox我正在尝试创建一个样式类来使用该包显示一个带有动态标题的框

\documentclass{article}
\usepackage[skins]{tcolorbox}
\tcbset{
    .exercise_box/.style={
        skin=widget,
        boxrule=1mm,
        coltitle=black,
        colframe=blue!45!white,
        colback=blue!15!white,
        title={Non Mutually Exclusive Events}
    }
}

\newtcolorbox{exercise_box}{.exercise_box}

\begin{document}

    \begin{exercise_box}[title={example 4}]
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

    \begin{exercise_box}[title={example 4.5}]
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

    \begin{exercise_box}[title={example 5}]
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

\end{document}

并得到以下结果

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

但框的标题不会以任何方式修改并且始终显示默认标题“非互斥事件”。

你可以帮帮我吗?

谢谢。

答案1

也许是这样的:

\documentclass{article}
\usepackage[skins]{tcolorbox}


\newtcolorbox{exercise_box}[1][Non Mutually Exclusive Events]{ 
    skin=widget,
    boxrule=1mm,
    coltitle=black,
    colframe=blue!45!white,
    colback=blue!15!white,
    title=#1}

\begin{document}

    \begin{exercise_box}[example 4]
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

    \begin{exercise_box}[example 4.5]
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

    \begin{exercise_box}
        If A and B are two events that are not mutually exclusive then:  
        \tcblower
        $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
    \end{exercise_box}

\end{document}

“非相互...”是默认标题,如果您不指定自定义标题,则会显示该标题。要指定自定义标题,只需填写可选参数即可。

在此处输入图片描述

相关内容