tcolorbox
我有以下代码使用该包生成“示例列表” :
\documentclass{article}
\usepackage{tcolorbox}
\newtcolorbox[auto counter, list inside=exam]{texample}[1][]{
breakable,
boxsep=0pt,
leftrule=4pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
top=0pt,
bottom=0pt,
before skip=\topsep,
after skip=\topsep,
arc=0pt,
outer arc=0pt,
colback=white,
colframe=gray!40,
oversize,
title={Example~\thetcbcounter},
fonttitle=\normalfont\bfseries,
coltitle=black,
fontupper=\itshape,
detach title,before upper={\tcbtitle\hspace{0.5em}}
}
\begin{document}
\tcblistof[\section*]{exam}{Lista de Exemplos}
\pagebreak
\begin{texample}
test
\end{texample}
\end{document}
运行此代码后,列表如下所示:
但我希望它看起来与此类似:
因此,我想要以下内容:
- “示例列表”应居中
- 列表中的每个项目都应为“示例 1 - 示例标题”
我该怎么做?
答案1
这是我想出的一个解决方案(虽然可能不是最好的解决方案,但似乎有效)
\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbset{
myexamplestyle/.style={
boxsep=0pt,
leftrule=4pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
top=0pt,
bottom=0pt,
before skip=\topsep,
after skip=\topsep,
arc=0pt,
outer arc=0pt,
colback=white,
colframe=gray!40,
oversize,
title={Example~\thetcbcounter},
fonttitle=\normalfont\bfseries,
coltitle=black,
fontupper=\itshape,
detach title,before upper={\tcbtitle\hspace{0.5em}},
separator sign={\ -}
}
}
\newtcbtheorem[auto counter, list inside=exam]{myexample}{Example}{myexamplestyle}{}
\makeatletter
\renewcommand{\l@tcolorbox}{\@dottedtocline{1}{0pt}{2.3em}}
\makeatother
\begin{document}
\begingroup
\renewcommand\numberline[1]{Example #1 - }
\tcblistof[\section*]{exam}{\centering Lista de Exemplos}
\endgroup
\begin{myexample}{Title of example}{}
Example of an example
\end{myexample}
\begin{myexample}{Title of second example}{}
Second example of an example
\end{myexample}
\end{document}
在此代码中,我从使用 tcolorbox 切换到 tcbtheorem,它允许您为示例命名。此代码\renewcommand{\l@tcolorbox}{\@dottedtocline{1}{0pt}{2.3em}}
用于修复列表中的一些间距问题。此代码\renewcommand\numberline[1]{Example #1 - }
将标签添加到列表中每个条目的前面。