我正在尝试将以下算法拆分成两个不同的幻灯片。有人能帮我吗?我该怎么做?
\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}
答案1
\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}