1

I am trying to split the following algorithm into two different slides. Can anyone help me how can I do this?

 \documentclass{beamer}
    \usepackage{beamerthemesplit} % new
    \usetheme{Warsaw} 
    \numberwithin{equation}{section}
    \usepackage{graphics,graphicx}
    \mode<presentation>
    \usepackage{algorithm}
    \usepackage{algpseudocode}
    \usepackage{algcompatible}
\begin{document}
{

\subsection{Algorithm}

\frame {\frametitle{Algorithm}

\begin{algorithm}[H] \caption{Primal Active-Set Method for Convex QP}

\begin{algorithmic}[1]
\State \texttt{Compute a feasible starting point $x_0$;}
\State \texttt{Set $\mathcal{W}_0$ to be a subset of the active constraints at $x_0$;}

    %\
    %\Set $\mathcal{W}_0$ to be a subset of the active constraints at $x_0$;
   \For{\texttt{k = 0, 1, 2, ....}}
            \State \texttt{solve to find $p_k$;}
            \If{\texttt{$p_k=0$}}
                \State \texttt{Compute Lagrange multipliers $\hat{\lambda_i}$that satisfy,} 
        \State \texttt{ with $\hat{\mathcal{W}}=\mathcal{W}_k$}
        \If{\texttt{$\hat{\lambda_i}\geq 0$ for all $i \in \mathcal{W}_k \cap \mathcal{I}$ }}
            \State \texttt{stop with the solution $x^*=x_k$;}

        \Else
            \State \texttt{$j \leftarrow$ arg min$_{j \in \mathcal{W}_k\cap \mathcal{I}} ~\hat{\lambda_j}$ ;}
            \State \texttt{$x_{k+1} \leftarrow x_k;$~$\mathcal{W}_{k+1} \leftarrow \mathcal{W}_k/ \{j\}$;}
        \EndIf
    %\EndIf

    \algstore{myalg}

\end{algorithmic} \end{algorithm} } \frame{

\begin{algorithm}
\begin{algorithmic} [1] % enter the algorithmic environment \algrestore{myalg}

    \Else{\texttt{($p_k \neq 0$)}}
        \State \texttt{Compute $\alpha_k$ from ;}
        \State \texttt{$x_{k+1} \leftarrow x_k + \alpha_k p_k$;}
        \If{\texttt{there are blocking constraints}}
            \State \texttt{Obtain $\mathcal{W}_{k+1}$ by adding one of the blocking constraints to $\mathcal{W}_k$;}
        \Else
            \State \texttt{$\mathcal{W}_{k+1} \leftarrow \mathcal{W}_k;$}
        \EndIf

    \EndIf


  \EndFor


\end{algorithmic}
\label{alg_1}

\end{algorithm}

}

\end{document}

User123
  • 11
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Willoughby Apr 05 '22 at 23:02
  • @Willoughby I updated my question. Thank you for the direction. – User123 Apr 05 '22 at 23:16
  • You can do it manually following instructions in https://tex.stackexchange.com/a/29817/1952 – Ignasi Apr 06 '22 at 09:59
  • @Ignasi I tried to split the way given in the link, but my issue is that how to continue the for loop and if statement in the next slide. I made the changes in my question. – User123 Apr 07 '22 at 20:50

1 Answers1

0
 \documentclass{beamer}
    \usepackage{beamerthemesplit} % new
    \usetheme{Warsaw} 
    \numberwithin{equation}{section}
%    \usepackage{graphics,graphicx}
    \mode<presentation>
    \usepackage{algorithm}
    \usepackage{algpseudocode}
    \usepackage{algcompatible}

    \usepackage{caption}
    \begin{document}

    \subsection{Algorithm}
\begin{frame}[allowframebreaks]
\frametitle{Algorithm}

%\begin{algorithm}[H]
    \captionof{algorithm}{Primal Active-Set Method for Convex QP}

    \begin{algorithmic}[1]
    \State \texttt{Compute a feasible starting point $x_0$;}
    \State \texttt{Set $\mathcal{W}_0$ to be a subset of the active constraints at $x_0$;}

        %\
        %\Set $\mathcal{W}_0$ to be a subset of the active constraints at $x_0$;
       \For{\texttt{k = 0, 1, 2, ....}}
                \State \texttt{solve to find $p_k$;}
                \If{\texttt{$p_k=0$}}
                    \State \texttt{Compute Lagrange multipliers $\hat{\lambda_i}$that satisfy,} 
            \State \texttt{ with $\hat{\mathcal{W}}=\mathcal{W}_k$}
            \If{\texttt{$\hat{\lambda_i}\geq 0$ for all $i \in \mathcal{W}_k \cap \mathcal{I}$ }}
                \State \texttt{stop with the solution $x^*=x_k$;}

            \Else
                \State \texttt{$j \leftarrow$ arg min$_{j \in \mathcal{W}_k\cap \mathcal{I}} ~\hat{\lambda_j}$ ;}
                \State \texttt{$x_{k+1} \leftarrow x_k;$~$\mathcal{W}_{k+1} \leftarrow \mathcal{W}_k/ \{j\}$;}
            \EndIf
        %\EndIf

%        \algstore{myalg}
%\end{algorithmic}
%\end{algorithm}
%}
%\frame{
%
%\begin{algorithm}                     
%\begin{algorithmic} [1]                   % enter the algorithmic environment
%\algrestore{myalg}

        \Else{\texttt{($p_k \neq 0$)}}
            \State \texttt{Compute $\alpha_k$ from ;}
            \State \texttt{$x_{k+1} \leftarrow x_k + \alpha_k p_k$;}
            \If{\texttt{there are blocking constraints}}
                \State \texttt{Obtain $\mathcal{W}_{k+1}$ by adding one of the blocking constraints to $\mathcal{W}_k$;}
            \Else
                \State \texttt{$\mathcal{W}_{k+1} \leftarrow \mathcal{W}_k;$}
            \EndIf

        \EndIf


      \EndFor


    \end{algorithmic}
    \label{alg_1}
%\end{algorithm}



%}

\end{frame}

    \end{document}