开发者

Latex: Change the numbering style for algorithms [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This questi开发者_Python百科on does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 3 years ago.

Improve this question

My problem is that I do not know how to change the numbering style for algorithms. I have created an algoritm and its number is "Algorithm 1", but I want to have "Algorithm N.1", where N is the number of current chapter.

Let assume I have something like below

\begin{algorithm}
    \begin{algorithmic}
        \FOR{$i = 1$ till end}
            \STATE do something
        \ENDFOR
     \end{algorithmic}
     \label{aForLoop}
     \caption{some caption}
 \end{algorithm}

Any help will appreciated.


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.


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}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜