8

I am using the algorithm2e package to write algorithms. However, when i write three algorithms one after another, the algorithms are automatically numbered 1,2 and 3 in the caption. I am using following code:

\begin{algorithm}[H]
 \SetAlgoLined
 \KwData{this text}
 \KwResult{how to write algorithm with \LaTeX2e }
 initialization\;
 \While{not at end of this document}{
  read current\;
 \eIf{understand}{
  go to next section\;
 current section becomes this one\;
 }{
 go back to the beginning of current section\;
 }
}
\caption{How to write algorithms}
\end{algorithm}

I am getting the resulting algorithm to be enter image description here

The caption of algorithm mentions "Algorithm 3" if this package is used three times. I want that for every caption it just mentions "Algorithm" and not "Algorithm 3". How can it be done?

6

If you're willing to use \TitleOfAlgo instead (which, for algorithms, is more flexible than \caption in many ways), then see John Wickerson's answer.

Otherwise, if you really want to use \caption but remove algorithm numbering, simply insert \renewcommand{\thealgocf}{} in your preamble.

enter image description here

\documentclass[10pt]{report} 
\usepackage{algorithm2e}

\renewcommand{\thealgocf}{}

\begin{document}

\begin{algorithm}[H]
 \SetAlgoLined
 \KwData{this text}
 \KwResult{how to write algorithm with \LaTeX2e }
 initialization\;
 \While{not at end of this document}{
  read current\;
 \eIf{understand}{
  go to next section\;
 current section becomes this one\;
 }{
 go back to the beginning of current section\;
 }
}
\caption{How to write algorithms}
\end{algorithm}

\end{document}
  • \renewcommand{\thealgocf}{} works for me – wannik May 16 '15 at 16:43
2

As texenthusiast has pointed out in a comment below, you should use

\TitleOfAlgo{How to write algorithms}

rather than

\caption{How to write algorithms}

This makes algorithms not numbered by default. If you change your mind and want the algorithms to be numbered again, you should set the option titlenumbered option when you load the algorithm2e package. (titlenotnumbered is the default.) That is,

\usepackage[titlenumbered]{algorithm2e}

For more details, see page 20 of the package documentation.

  • 2
    titlenotnumbered is (default) hence not needed to mention but should use \TitleOfAlgo{How to write algorithms} instead of \caption{How to write algorithms} to remove numbering. – texenthusiast May 18 '13 at 8:04
  • This is not a solution for me, because I need the \RestyleAlgo{boxruled} style, which doesn't work as I want when using \TitleOfAlgo. – marktani May 16 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.