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.
Best Answer
The right counter is
algocf
and notalgorithm
. Also you have to use\resetcounteronoverlays
instead of\resetcountonoverlays
sincealgocf
is defined asIn other words, adding the following line in your preamble
solves the issue.
MWE:
Output