我已经创建了自己的环境example
,类似于theorem
。现在我想生成一个示例列表,类似于表格列表或图形列表。我该如何实现?
答案1
您所需要的是 U. Schwarz 开发的 thmtools 软件包:
\usepackage{thmtools}
\renewcommand{\listoftheoremname}{List of examples}
...
\begin{document}
...
\listoftheorems[ignoreall,show={example}]
对于定理标签中的脚注,您可以使用通常的技巧和来完成\footnotemark
,\footnotetext
但是为了避免在定理列表中使用脚注标记,还需要另一个技巧:
\usepackage{thmtools}
\declaretheorem[name=Example]{example}
\renewcommand{\listoftheoremname}{List of examples}
...
\begin{document}
...
\begingroup
\let\footnotemark\relax
\listoftheorems[ignoreall,show={example}]
\endgroup
...
\begin{example}[name=Nice example\protect\footnotemark]
\footnotetext{Due to E. X. Ample}%
This is a very nice example
\end{example}
您不想在列表中添加脚注标记,是吗?:)
---其他格式---
负责在文件中写入条目的宏,loe
该文件用于排版示例列表\ll@example
。您可以获得一个仅显示示例名称的列表,方法是在相关\declaretheorem
\makeatletter
\def\ll@example{%
\protect\numberline{\csname the\thmt@envname\endcsname}%
\ifx\@empty\thmt@shortoptarg
\thmt@thmname
\else
\thmt@shortoptarg
\fi}
\makeatother
答案2
答案3
你为什么不使用float
已经建议的?它类似于图表和表格,有据可查:
在之前添加\begin{document}
:
\usepackage{float}
\floatstyle{plain}
\newfloat{example}{thp}{loc}[chapter]
\floatname{example}{Example}
将其添加到您想要列表的位置:
\listof{example}{List of examples}
如果您也想在目录中添加此内容,请添加:
\addcontentsline{toc}{chapter}{List of examples}
当然还要定义一个小例子:
\begin{example}
This is a small example.
\caption[Small example]{Small example - you can add links and other stuff here}
\label{example:foo}
\end{example}
并引用它:
As you can see in Example \ref{example:foo}, ...
答案4
以下是我的解决方案。通过在后面添加 [] \begin{example}
,您可以添加标签,以便稍后引用该示例。
\documentclass{scrartcl}
\usepackage{tocloft,
lipsum}
\usepackage[framemethod=tikz]{mdframed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define the List
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\listexamplename}{List of Examples} % Set the name of the list
\newlistof{examples}{exp}{\listexamplename} % First bracket is \listof{what's in here}, second is the document that will be created, NameOfYourDoc.exp in this case. Third is title of the list, what you define in above \newcommand.
\newcommand{\examples}[1]{% How to set a counter for.
\refstepcounter{examples} %increase the counter
\par\noindent\textbf{Example \theexamples: #1} %The text that will be used when \examples is used.
\addcontentsline{exp}{examples} % Add the line to the .exp file
{\protect\numberline{\theexamples}#1}\par} %I do not understand this, maybe somebody can explain.
\setlength{\cftexamplesindent}{1.5em} %Indent of the example #. Same as \listoffigures
\setlength{\cftexamplesnumwidth}{2.3em} %Indent of the examples title. Same as \listoffigures
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define the Frame
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mdfsetup{frametitlealignment=\center}
\newmdenv[linecolor=white,
roundcorner=10pt,
backgroundcolor=gray!50,
frametitleaboveskip=10pt,
skipbelow=5pt,
innerbottommargin=12pt
]{example}
\makeatletter
\let\orig@example=\example %This part is used to define the env with and without label
\DeclareRobustCommand\example{\@ifnextchar[{\@@example}{\@example}} %It scans for [ and then decides what to use.
\def\@@example[#1]#2{ %Case with label
\orig@example[frametitle=\examples{{#2}}\label{#1}]
}
\def\@example#1{ %Case without label
\orig@example[frametitle=\examples{{#1}}]
}
\makeatother
\begin{document}
You can reference to an example, see example \ref{exp:label}, or not. You can also use the list outside by using \examples{Title}.
\begin{example}[exp:label]{Title of Example with label}
\lipsum[1]
\end{example}
\begin{example}{Title of Example without label}
\lipsum[1]
\end{example}
\listofexamples
\end{document}
这导致