12

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?

2

3 Answers 3

11

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}
1
  • 2
    \renewcommand{\thealgocf}{} works for me
    – wannik
    Commented May 16, 2015 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.

3
  • 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. Commented May 18, 2013 at 8:04
  • 3
    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
    Commented May 16, 2019 at 20:28
  • Is there a way to also remove the "Algorithm" and just have it be it's title?
    – lpnorm
    Commented Jun 24, 2023 at 14:44
0

Just use

\usepackage[ruled,vlined,linesnumberedhidden,algo2e,resetcount,algochapter]{algorithm2e}

in place of

\usepackage{algorithm2e}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .