我有一些通常没有编号的 tcbtheorems,但我希望能够灵活地使用它们以及编号。
这是一个简单的例子:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{multicol}
\tcbset{
detach title,
fonttitle=\bfseries,
coltitle=black,
before upper={\tcbtitle},
terminator sign={.},
}
\newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}
\newtcbtheorem[]{myproof2}{Proof}{ colframe=red, before upper={\tcbtitle~} }{}
\newtcbtheorem[]{myproof3}{Proof}{ colframe=blue, terminator sign={.~} }{}
\begin{document}
\begin{multicols}{2}
\begin{myproof1*}{}{}
This is a proof.
\end{myproof1*}
\begin{myproof2*}{}{}
This is a proof.
\end{myproof2*}
\begin{myproof3*}{}{}
This is a proof.
\end{myproof3*}
\begin{myproof1}{}{}
This is a proof.
\end{myproof1}
\begin{myproof2}{}{}
This is a proof.
\end{myproof2}
\begin{myproof3}{}{}
This is a proof.
\end{myproof3}
\end{multicols}
\end{document}
我通常设置灰色盒子,它工作得很好,直到我决定使用编号。数字和盒子的内容之间应该有一个空格。
我尝试通过在标题后添加波浪号(红色框)或在终止符后添加波浪号(蓝色框)来修复此行为。 两者都按预期工作,但现在未编号的框中有一个额外的空格。
答案1
虽然由定义的无星号定理环境\newtcbtheorem
需要一个可选参数和两个强制参数,但带星号的版本需要一个可选参数,并且仅一强制性论点。
因此\newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}
,应该使用
\begin{myproof1}[<options>]{<thm name>}{<label>} ... \end{myproof1}
\begin{myproof1*}[<options>]{<thm name>} ... \end{myproof1*}
在 OP 的例子中,添加到带星号的环境中第二个空白会取消使用时自动插入{}
的效果,因此导致空格不一致。\ignorespace
before upper={...}
也就是说,在使用
\begin{myproof1*}{}{}
This is a proof
\end{myproof1*}
上面的部分从第二个开始{}
,因此变成
\tcbtitle\ignorespaces{}<space>This is a proof
% this <space>, coming from the newline character, is not ignored
虽然使用得当
\begin{myproof1*}{}
This is a proof.
\end{myproof1*}
上部是
\tcbtitle\ignorespaces<space>This is a proof
% this <space> is ignored by \ignorespaces
除去多余的牙套,你就可以选择before upper={\tcbtitle~}
或terminator sign={.~}
。
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{multicol}
\tcbset{
detach title,
fonttitle=\bfseries,
coltitle=black,
before upper={\tcbtitle},
terminator sign={.},
}
\newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}
\newtcbtheorem[]{myproof2}{Proof}{ colframe=red, before upper={\tcbtitle~} }{}
\newtcbtheorem[]{myproof3}{Proof}{ colframe=blue, terminator sign={.~} }{}
\begin{document}
\begin{multicols}{2}
\begin{myproof1*}{}%{}
This is a proof.
\end{myproof1*}
\begin{myproof2*}{}%{}
This is a proof.
\end{myproof2*}
\begin{myproof3*}{}%{}
This is a proof.
\end{myproof3*}
\begin{myproof1}{}{}
This is a proof.
\end{myproof1}
\begin{myproof2}{}{}
This is a proof.
\end{myproof2}
\begin{myproof3}{}{}
This is a proof.
\end{myproof3}
\end{multicols}
\end{document}