1

I'm making slides with beamer. My algorithm is a little bit long so that I cannot put it in one slide. I need to divide it from the middle of it and display it in two slides. What should I do?

\usepackage[ruled]{algorithm2e}

\begin{frame}[allowframebreaks]

    \begin{algorithm}[H] 
    \footnotesize
        \caption{What should I do?}
        \KwIn{$\{\bm{K}_m\},C$.}
        \KwOut{$\bm{\alpha},\bm{d}$.}
        set someting;
        \While{stopping criterion not met}{
            compute sth.\;
            compute sth.\;
            set sth.\;
            computing sth.\;
            set sth.\;
            \While{sth.}{
                sth.\;
                sth.\;
                sth.\;
                sth.\;
                sth.\;
                sth.\;
            }
        }
    \end{algorithm}

\end{frame}
Bernard
  • 271,350
WuSiren
  • 21

1 Answers1

4

Based on https://tex.stackexchange.com/a/347920/36296 you could do something like this:

\documentclass{beamer}

\usepackage[ruled]{algorithm2e}


\begin{document}

\begin{frame}

\begin{onlyenv}<1>
 \begin{algorithm}[H] 
% This is to hide end and get the last vertical line straight
\SetKwBlock{Begin}{Begin}{}
\SetAlgoLined
  \Begin{
  $\mathcal{E} \leftarrow \emptyset$\;
  }
\end{algorithm}
\end{onlyenv}

\begin{onlyenv}<2>
\begin{algorithm}[H]
%This is to hide Begin keyword
\SetKwBlock{Begin}{}{end}
\Begin{
  $\mathcal{E} \leftarrow \emptyset$\;
  $\mathcal{E} \leftarrow \emptyset$\;
  $\mathcal{E} \leftarrow \emptyset$\;
  $\mathcal{E} \leftarrow \emptyset$\;
  $\mathcal{E} \leftarrow \emptyset$\;     
  }
\end{algorithm}
\end{onlyenv}

\end{frame}

\end{document}

enter image description here