Latex:更改算法的编号样式

发布于 2024-10-03 05:36:44 字数 1549 浏览 1 评论 0 原文

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

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

发布评论

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

评论(3

浅暮の光 2024-10-10 05:36:44

这个问题已经有8年历史了,接受的答案中的链接不再有效,所以我将在这里发布一个答案以供将来参考。此外,它属于 tex.stackexchange.com。

只需将 [chapter] (或 [section])添加到包声明中

\usepackage[chapter]{algorithm}

,并确保算法中按顺序有标题和标签:

\caption{The Foo Algorithm}
\label{algorithm:foo}

This question is already 8 years old and the link in the accepted answer doesn't work anymore, so I'll post an answer here for future reference. Also, it belongs on tex.stackexchange.com.

Just add the [chapter] (or [section]) to the package declaration

\usepackage[chapter]{algorithm}

and make sure to have a caption and a label in the algorithm, in that order:

\caption{The Foo Algorithm}
\label{algorithm:foo}
情绪少女 2024-10-10 05:36:44

如文档中所示:

可以通过提供应重新开始编号的文档组件的名称来影响算法的编号。该选项的合法值为:part、chapter、section、subsection、subsubsection 或无。默认值是空的,这会导致算法在整个文档中按顺序编号。

因此,我认为确定 section 值就足够了,如下所示:

\begin{algorithm}[section]
...

未测试,但应该有效。

As in the documentation:

The numbering of algorithms can be influenced by providing the name of the document component within which numbering should be recommenced. The legal values for this option are: part, chapter, section, subsection, subsubsection or nothing. The default value is nothing which causes algorithms to be numbered sequentially throughout the document.

So, I think it will be enough determining the section value, like that:

\begin{algorithm}[section]
...

Didn't test, but should work.

很酷又爱笑 2024-10-10 05:36:44

此页面解释得很好: https://web.archive.org/web/20100901100351/https://www.iam.ubc.ca/old_pages/newbury/tex/numbering.html

我认为这适用于算法以及通过重新定义 \thealgorithm 命令,事实上,我在德国论坛上读到,用户设法通过重新定义它来禁用算法编号,所以它应该可以工作。

This page explains it quite well: https://web.archive.org/web/20100901100351/https://www.iam.ubc.ca/old_pages/newbury/tex/numbering.html

I assume this would work for algorithms as well by redefining the \thealgorithm command, in fact I read on a German forum that a user managed to disable numbering for algorithms by redefining this, so it should work.

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