Consider the following minimal example:
\documentclass[usenames,dvipsnames]{beamer}
\usepackage[linesnumbered,boxed,ruled,vlined,resetcount]{algorithm2e}
\begin{document}
\begin{frame}[fragile]
With caption:
\begin{algorithm}[H]
\KwIn{ $x, y$ }
\KwOut{$z$}
$z = x\cdot y + 1$
\Return $z$
\caption{$FindZ$}
\end{algorithm}
\vspace*{0.5cm}
Without caption:
\begin{algorithm}[H]
\TitleOfAlgo{$FindZ$}
\KwIn{ $x, y$ }
\KwOut{$z$}
$z = x\cdot y + 1$
\Return $z$
\end{algorithm}
\end{frame}
\end{document}
It generates the following slide with two algorithms:
In the first one, I used the command \caption and the nice thing is that the title appears between the two horizontal lines just before describing the input. But I don't like the number.
Following some answers I found here in tex.stackexchange, instead of \caption, I used \TitleOfAlgo in the second algorithm. Now I don't have the number in front of the word "Algorithm", but the title counts as a line of the algorithm (it is numbered as line 1). Also, it doesn't appear between the two lines (we see the two lines above it).
Is there a way of obtaining the same thing I obtain with Caption, but showing no number in front of "Algorithm" nor making it a numbered line?
Best Answer
Using
\RemoveAlgoNumber
from algorithm title, which is unnumbered, is not in place allows you to switch algorithm numbering on/off. If done within aframe
, it'll be temporary:Note that the algorithm number is still incremented. However, since this forms part of a (
beamer
) presentation, it's best to avoid numbering content and rather refer to them by name anyway. That is, use\RemoveAlgoNumber
in the preamble to turn all algorithm numbering off.