0

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}
  • 3
    Welcome to TeX.SE. It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – user36296 Mar 11 at 15:46
  • Thanks for updating your post. Can you add all the packages necessary to compile your code fragment? – user36296 Mar 11 at 16:06
3

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

  • Thanks. How about while loop? – WuSiren Mar 12 at 3:40
  • Thanks. How about while loop like while sth. do ...? – WuSiren Mar 12 at 3:41
  • @WuSiren You can split the while loop the same way as the \begin block in my example: \SetKwFor{While}{...}{...}{...} – user36296 Mar 12 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.