7

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.

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

1 Answer 1

9

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

\newcounter{algocf}

In other words, adding the following line in your preamble

\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

enter image description here enter image description here

You must log in to answer this question.

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