# Making algorithm2e environments "overlay aware" in beamer

What is the right away to make algorithms overlay aware in beamer?

When using algorithm2e in a beamer presentation, an algorithm on a frame with overlays can get more than one number.

For example, this code produces two slides, on which the same algorithm gets two different numbers.

\documentclass{beamer}
\usepackage[boxruled,vlined,linesnumbered]{algorithm2e}
\usepackage{hyperref}

\begin{document}
\begin{frame}\frametitle{my algorithm}
\begin{algorithm}[H] \caption{my algorithm}
do this\;
then do that\;
\end{algorithm}

\pause

Some explanations.
\end{frame}
\end{document}


The issue appears to be that the algorithm environment is not "overlay aware". I tried using

\resetcountonoverlays{algorithm}


but that just stopped the file from compiling entirely.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Feb 6 '15 at 20:01

The right counter is algocf and not algorithm. Also you have to use \resetcounteronoverlays instead of \resetcountonoverlays since algocf is defined as

\newcounter{algocf}


\resetcounteronoverlays{algocf}


solves the issue.

MWE:

\documentclass{beamer}
\usepackage[boxruled,vlined,linesnumbered]{algorithm2e}
\usepackage{hyperref}
\resetcounteronoverlays{algocf}

\begin{document}
\begin{frame}\frametitle{my algorithm}
\begin{algorithm}[H] \caption{my algorithm}
do this\;
then do that\;
\end{algorithm}

\pause

Some explanations.
\end{frame}
\end{document}


Output