我正在使用tcolorbox
在我的论文中设置几个定理。问题是,最长的“名称”(他们在文档中称之为描述)是只是一行太长了。
这是一个 MWE(这是我想要使用的有点定制的风格):
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\definecolor{theoremgray}{rgb}{0.93, 0.93, 0.93}
\newtcbtheorem{theorem}{Theorem}%
{
enhanced,
frame empty, breakable,
colframe=black, coltitle=black,
fonttitle=\bfseries , colbacktitle=white,
fontupper=\slshape, colback=theoremgray,
borderline={0.5mm}{0mm}{theoremgray},
attach boxed title to top left,,
boxed title style={boxrule=0.5mm, rounded corners},
boxed title size={copy},
minipage boxed title
}{theo}
\begin{document}
\begin{theorem}{This is a slightly too long title that just causes a break}{test1}
Some text in my theorem.
\end{theorem}
\end{document}
我想做的是设置它,只在标题框的第一行写“定理 1:”,在第二行写名称(描述),但是,它应该直接在“定理 1:”下面开始。这样,整个内容就可以放在一行中。我查看了软件包的文档,tcolorbox
并尝试了几种方法,例如使用separator sign={\newline}
(对我没有任何作用)或description formatter=\newline
从新行开始描述,但对齐方式错误。
有没有办法做到这一点?
答案1
更新:
使用v4.50 (2021/05/21) 或更新版本,可以使用(我的功能请求中建议的新添加的键)tcolorbox
来实现此目的theorem hanging indent=0pt
tcolorbox#126
。
以下示例已更新,以兼容tcolorbox
v4.50 之前的版本和不早于 v4.50 的版本。
原始答案:
\tcb@theo@title
这修补了用于排版 tcb 定理标题的内部宏,并删除了悬挂缩进部分。
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\usepackage{xpatch}
\definecolor{theoremgray}{rgb}{0.93, 0.93, 0.93}
\newtcbtheorem{theorem}{Theorem}%
{
enhanced,
frame empty, breakable,
colframe=black, coltitle=black,
fonttitle=\bfseries , colbacktitle=white,
fontupper=\slshape, colback=theoremgray,
borderline={0.5mm}{0mm}{theoremgray},
attach boxed title to top left,,
boxed title style={boxrule=0.5mm, rounded corners},
boxed title size={copy},
minipage boxed title,
separator sign={},
description formatter=\newline,
% use pgfkeys handler `/.try` to keep backward compatibility
theorem hanging indent/.try=0pt,
}{theo}
\makeatletter
% for tcolorbox before v4.50 (2021/05/21), patch \tcb@theo@title
% usage: title={\tcb@theo@title{Theorem}{\thetcbcounter}{<description>}}
\IfPackageAtLeastTF{tcolorbox}{2021/05/21}{
}{
\xpatchcmd\tcb@theo@title
{\hangindent\wd\z@\hangafter=1}
{}
{}{\fail}
}
\makeatother
\begin{document}
\begin{theorem}{This is a slightly too long title that just causes a break}{test1}
Some text in my theorem.
\end{theorem}
\end{document}