![如何使用相同的样式更改不同 tcolorbox 中的标题](https://linux22.com/image/339409/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E7%9B%B8%E5%90%8C%E7%9A%84%E6%A0%B7%E5%BC%8F%E6%9B%B4%E6%94%B9%E4%B8%8D%E5%90%8C%20tcolorbox%20%E4%B8%AD%E7%9A%84%E6%A0%87%E9%A2%98.png)
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}
“非相互...”是默认标题,如果您不指定自定义标题,则会显示该标题。要指定自定义标题,只需填写可选参数即可。