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:
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:
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.
发布评论
评论(3)
这个问题已经有8年历史了,接受的答案中的链接不再有效,所以我将在这里发布一个答案以供将来参考。此外,它属于 tex.stackexchange.com。
只需将
[chapter]
(或[section]
)添加到包声明中,并确保算法中按顺序有标题和标签:
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 declarationand make sure to have a caption and a label in the algorithm, in that order:
如文档中所示:
因此,我认为确定
section
值就足够了,如下所示:未测试,但应该有效。
As in the documentation:
So, I think it will be enough determining the
section
value, like that:Didn't test, but should work.
此页面解释得很好: 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.