我试图弄清楚如何始终将默认分隔符添加到我的自定义中tcbtheorem
。
正如标题所示,我使用tcolorbox
包并用 定义环境newtcbtheorem
。 分隔符(标准:
)仅在给出标题时显示。
我对这个文档的了解还不够深入。
答案1
在下面的示例中,提供了一个新的tcolorbox
布尔选项。force separator sign
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{xpatch}
\makeatletter
% new tcolorbox boolean option "force seperator sign"
\newif\iftcb@thm@separatorsign
\tcbset{
force seperator sign/.is if=tcb@thm@separatorsign,
force seperator sign/.default=true
}
\xpatchcmd\tcb@theo@title
{\unhbox\z@\kvtcb@terminatorsign}
{\mbox{\unhbox\z@\iftcb@thm@separatorsign\kvtcb@separatorsign\fi}%
\kvtcb@terminatorsign
}
{}{\fail}
\makeatother
% thm env always shows "separator sign"
\newtcbtheorem{thm}{Theorem}{
separator sign=.,
colframe=blue!50!black,
force seperator sign
}{thm}
% cor env hides "seperator sign" if thm-title is empty
\newtcbtheorem{cor}{Corollary}{}{cor}
\begin{document}
\begin{thm}{}{}
``separator sign" is forced to be typeset in ``thm" env.
\end{thm}
\begin{thm}{Name}{}
``separator sign" is forced to be typeset in ``thm" env.
\end{thm}
\begin{cor}{}{}
content
\end{cor}
\begin{cor}{Name}{}
content
\end{cor}
\end{document}