我想在LaTeX文档中添加项目。比方说,我想为文档添加提示。我创建了一个命令,所以我可以调用类似的东西:
\hint{foocareful}{Be careful with foo!}{foo is a very precious item and can easily be broken. Be careful, especially don't throw foo.}
这将以特殊方式格式化,以便读者将其识别为提示。它得到一个标签,可以在示例中用'foocareful'引用。
在附录中,我想添加一个包含所有提示的列表。类似的东西:
\begin{enumerate}
...
\item Be careful with foo! (\pageref{foocareful})
...
\end{enumerate}
但我自然不想手工维护这个清单。如何自动创建这样的列表?
答案 0 :(得分:9)
一种方法是使用float
包。我认为,至少floatrow
包也可以做你想要的,也可能更灵活。不过,请你去看看。
以下是您尝试使用float
执行此操作的示例:
\documentclass{article}
\usepackage{float}
\floatstyle{boxed}
\newfloat{hintbox}{H}{hnt}
\floatname{hintbox}{Hint}
\newcommand\hint[2]{%
\begin{hintbox}
#2
\caption{#1}
\end{hintbox}}
\begin{document}
\section{Hello}
\hint{Be careful with foo!\label{foocareful}}{%
foo is a very precious item and can easily be broken.
Be careful, especially don't throw foo.}
\hint{Don't worry about bar!\label{foocareful}}{%
Unlike foo, bar is pretty easily to get along with.}
\section{End}
\listof{hintbox}{List of Hints}
\end{document}
答案 1 :(得分:2)
多年来没有这样做,但我会查看\ tableofcontents和\ listoffigures的LaTeX源代码。我认为该机制是通用的,您可以将其扩展为包含您自己的列表。