抱歉,问题描述不太好,但我的意思是您如何更新设置以支持使用 tcbcounter 的默认标题Example 1.1
或更具描述性的内容Example 1.1: Making a tcolorbox
- 帮助区分示例并提供描述,以便我以后可以轻松地返回它们。
我目前已更新此 tcolorbox,以支持列表和文本/评论;但是,我还想让标题像我上面描述的那样工作。以下是该框的代码(带有示例这里):
\newtcblisting[auto counter, number within=section, list inside=examplelist]{tcbexample}[2][]{%
colback=gray!5, colbacktitle=gray!40, coltitle=black,
frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
fonttitle=\bfseries, breakable, enhanced, parbox=false,
segmentation style={solid, draw=gray!20, line width=1pt}, % personal update
comment and listing,
title=Example~\thetcbcounter,
comment={#2},#1
}
有没有办法改变 tcolorbox 的设置来改变标题,以便它可以反映更具描述性的内容,例如Example 1.1: Making a tcolorbox
(但当此类输入留空时,它默认为Example 1.1
?谢谢!
答案1
您可以使用以下after title
密钥:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{breakable, listings, skins}
\newtcblisting[auto counter, number within=section, list inside=examplelist]{tcbexample}[2][]{%
colback=gray!5, colbacktitle=gray!40, coltitle=black,
frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
fonttitle=\bfseries, breakable, enhanced, parbox=false,
segmentation style={solid, draw=gray!20, line width=1pt}, % personal update
comment and listing,
title=Example~\thetcbcounter,
comment={#2},#1
}
\pgfkeysifdefined{/tcb/name}{\fail}{
\tcbset{
name/.style={after title={: #1}}
}
}
\begin{document}
\section{title}
\begin{tcbexample}[name=title]{comment}
code
\end{tcbexample}
\begin{tcbexample}{no title}
code
\end{tcbexample}
\end{document}
tcolorbox
有一个内置逻辑,用于将这种“可选名称”附加到标题(也检查键separator sign
),但不幸的是,它在内部是硬编码的\tcbnewtheorem
(更具体地说,\tcb@theo@title
),因此仅适用于tcolorbox
-定义定理环境。