# Split algorithm in two slides with beamer

I am following this answer, but no luck as you can see:

The frame is being split into two slides, but the first slide is left empty! How to fix this?

\documentclass{beamer}

\def\RR{{\mathbb R}}
\def\Ss{{\mathbb S}}
\def\EE{{\mathbb E}}
\def\Pr{{\mathrm Pr}}
\def\dd{{\mathrm d}}
\def\ee{{\mathrm e}}
\def\MM{{\mathcal M}}
\def\sign{{\mathrm sign}}

\usepackage{algorithm}
\usepackage{algorithmic}
\newcommand{\algorithmicinput}{\textbf{input}}
\newcommand{\INPUT}{\item[\algorithmicinput]}
\newcommand{\algorithmicoutput}{\textbf{output}}
\newcommand{\OUTPUT}{\item[\algorithmicoutput]}

\begin{document}

\begin{frame}[allowframebreaks]{Search}
\begin{algorithm}[H]
\caption{Dolphinn: Query Algorithm}
\label{DolphinnQuery}
\begin{algorithmic}
\INPUT{Metric $(\MM, d_{\MM})$, LSH family $F$, data set $P \subset \MM$, parameter $d'$, integer StopSearch, query $q$. (We assume that this algorithm has access to the ANN data structure created in Algorithm \ref{DolphinnPrep})}
\OUTPUT{Point $p \in P$ or "no"}
%\STATE{Compute $f(q)=(f_1(h_1(q)), f_2(h_2(q)), \ldots, f_{d'}(h_{d'}(q)))$ as folows:}
\FOR{$i = 1$ to $d'$}
\IF{$f_i(h_i(q))$ is not defined in Algorithm \ref{DolphinnPrep}}
\STATE{Flip a fair coin and assign the result to $f_i(h_i(q))$.}
\ELSE
\STATE{Compute $f_i(h_i(q))$.}
\ENDIF
\ENDFOR

\STATE{i=0}
\FOR{\textbf{each} $x$ in $f(P)$ s.t. $\|x-f(q)\|_1\leq 0.5 \cdot d' \cdot (1-p_1)$ }
\FOR{\textbf{each} point $p$ inside the bucket with key $x$}
\IF{$d_{\MM}(p,q)\leq c\cdot r$}
\STATE \textbf{return} $p$.
\ENDIF
\STATE{$i\gets i+1$}
\IF{$i>StopSearch$}
\STATE \textbf{return} "no".
\ENDIF

\ENDFOR
\ENDFOR
\STATE{\textbf{return} "no"}

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

• try removing the "algorithm" environment? Commented Mar 1, 2017 at 20:17
• Thanks for adding the code. However even after adding the obviously missing documentclass etc. I cannot compile your code due to many Undefined control sequence. errors. Can you make a compilable MWE? Commented Mar 1, 2017 at 22:22

## 1 Answer

May something like this do the job?

\documentclass{beamer}

\def\RR{{\mathbb R}}
\def\Ss{{\mathbb S}}
\def\EE{{\mathbb E}}
\def\Pr{{\mathrm Pr}}
\def\dd{{\mathrm d}}
\def\ee{{\mathrm e}}
\def\MM{{\mathcal M}}
\def\sign{{\mathrm sign}}

\usepackage{algorithm}
\usepackage{algorithmic}
\newcommand{\algorithmicinput}{\textbf{input}}
\newcommand{\INPUT}{\item[\algorithmicinput]}
\newcommand{\algorithmicoutput}{\textbf{output}}
\newcommand{\OUTPUT}{\item[\algorithmicoutput]}

\usepackage{caption}

\begin{document}

\begin{frame}[allowframebreaks]{Search}
\rule{\textwidth}{0.5pt}
\captionof{algorithm}{Dolphinn: Query Algorithm}%
\vspace*{-0.5cm}
\rule{\textwidth}{0.5pt}%
\vspace*{-0.5cm}
%\begin{algorithm}[H]
%    \caption{Dolphinn: Query Algorithm}
\label{DolphinnQuery}
\begin{algorithmic}
\INPUT{Metric $(\MM, d_{\MM})$, LSH family $F$, data set $P \subset \MM$, parameter $d'$, integer StopSearch, query $q$. (We assume that this algorithm has access to the ANN data structure created in Algorithm \ref{DolphinnPrep})}
\OUTPUT{Point $p \in P$ or "no"}
%\STATE{Compute $f(q)=(f_1(h_1(q)), f_2(h_2(q)), \ldots, f_{d'}(h_{d'}(q)))$ as folows:}
\FOR{$i = 1$ to $d'$}
\IF{$f_i(h_i(q))$ is not defined in Algorithm \ref{DolphinnPrep}}
\STATE{Flip a fair coin and assign the result to $f_i(h_i(q))$.}
\ELSE
\STATE{Compute $f_i(h_i(q))$.}
\ENDIF
\ENDFOR

\STATE{i=0}
\FOR{\textbf{each} $x$ in $f(P)$ s.t. $\|x-f(q)\|_1\leq 0.5 \cdot d' \cdot (1-p_1)$ }
\FOR{\textbf{each} point $p$ inside the bucket with key $x$}
\IF{$d_{\MM}(p,q)\leq c\cdot r$}
\STATE \textbf{return} $p$.
\ENDIF
\STATE{$i\gets i+1$}
\IF{$i>StopSearch$}
\STATE \textbf{return} "no".
\ENDIF

\ENDFOR
\ENDFOR
\STATE{\textbf{return} "no"}

\end{algorithmic}
%\end{algorithm}
\end{frame}
\end{document}


• I am getting Undefined control sequence. <inserted text> ...\textwidth }{0.5pt} \captionof {algorithm}{Dolphinn: Quer... l.184 \end{frame}, any idea? Commented Mar 2, 2017 at 12:18
• Did you \usepackage{caption}? Commented Mar 2, 2017 at 12:19
• No, that was it! =) Commented Mar 2, 2017 at 12:20