如何自动创建 LaTeX 文档中使用的项目列表?

发布于 2024-07-08 23:56:55 字数 507 浏览 6 评论 0原文

我想在 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}

但我自然不想手动维护这个列表。 如何自动创建这样的列表?

I want to add items in a LaTeX-document. Say for example, that I want add hints to the document. I create a command, so I can call something similar to this:

\hint{foocareful}{Be careful with foo!}{foo is a very precious item and can easily be broken. Be careful, especially don't throw foo.}

This will be formatted in special way, to make it easy for the reader to recognize it as a hint. It gets a label, that can be referenced in the example with 'foocareful'.

In the appendix I want to add a list of all hints with references to them. Something like:

\begin{enumerate}
   ...
   \item Be careful with foo! (\pageref{foocareful})
   ...
\end{enumerate}

But naturally I don't want to maintain this list by hand. How can I create automatically such a list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗弃M 2024-07-15 23:56:55

一种方法是使用 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}

One way to do it is to use the float package. I think that, at least, the floatrow package can also do what you want, and may also be more flexible. See you go, though.

Here's an example of something like you're trying to do using 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}
怂人 2024-07-15 23:56:55

已经很多年没有这样做了,但我会查看 \tableofcontents 和 \listoffigures 的 LaTeX 源代码。 我认为该机制是通用的,您可以将其扩展以包含您自己的列表。

Have not done this in years, but I would look at the LaTeX source code for \tableofcontents and \listoffigures. I think the mechanism is generic and you can expand it to include your own lists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文