# Fit a long algorithm into a beamer presentation

I want to include the following algorithm in beamer frame. My MWE is shown below

\documentclass[11pt]{beamer}% http://ctan.org/pkg/beamer
\mode<presentation>

\usepackage{float}

\usepackage{algpseudocode,algorithm,algorithmicx}
\setbeamertemplate{frametitle}[default][center]

\usepackage{xkeyval}

\usepackage{etoolbox}
\usepackage{ragged2e}
\apptocmd{\frame}{}{\justifying}{} % Allow optional arguments after frame.

\setbeamertemplate{caption}[numbered]

\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry location}{}
\setbeamertemplate{bibliography entry note}{}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{epstopdf}

\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}
%\framesubtitle{\centerline{frame subtitle}}

\begin{algorithm}[H]
\caption{Pseudocode for the GWO}
\label{gwo}
\begin{algorithmic}[1]
%   \Procedure{Hybrid BAT-Genetic Algorithm}{}
\\Input :Grey wolf population:$X_{i}(i = 1, 2, ..., n)$,Maximum Number of iteration:Max\_it
\\Output :$X_{a}$ : Optimal Position(Optimized filter coefficients)
\\Objective function : PSNR
\hrule
\\Initialize the Grey wolf population $X_{i} = (i=1,2, ...,n)$
\\Initialize the coefficient vectors a, A, and C
\State $\vec{A}=2\vec{a}\vec{r_1}-\vec{a}$
\State $\vec{C}=2\vec{r_2}$
\Comment where components of are linearly decreased from 2 to 0 over the course of iterations and,\\ are random vectors in $[0,1]$
\For{all $X_{i}$}
\State Calculate fitness $F(X_{i})$ of all $X_{i}$
\EndFor
\State Rank the gray wolf in descending order based on the fitness
\State $X_{\alpha}$ = the first search agent
\State $X_{\beta}$ = the second search agent
\State $X_{\delta}$ = the third search agent
\State t=1;
\While{t\textless Max\_it}
\For{i=1:n}
\State Update the position of the current search agent $\vec{F}(t+1) = \frac{\vec{F_{1}}+\vec{F_{2}}+\vec{F_{3}}}{3}$
\EndFor
\State Update $a$,$A$, and $C$
\For{all $X_{i}$}
\State Calculate fitness $F(X_{i})$ of all $X_{i}$
\EndFor
\State Update $X_{\alpha}$, $X_{\beta}$, and $X_{\delta}$
\State t=t+1;
\EndWhile
\State Return the first best agent $X_{\alpha}$ found so far
\\Post-processing the results and visualization
%   \EndProcedure
\end{algorithmic}
\end{algorithm}

\end{frame}
\end{document}

• I guess the problem is that the agorithm does not fit on a beamer slide. The idea with beamer is to make presenteations, and as such I normally view everything that does not fit in a frame as too detailed. I think there is a risk that you will lose some of the attention from the audience with a slide like this. My advice would be to describe the algorithm in (much) less details. Then it will both fit the slide and people will have chance to understand it. – StefanH Jun 20 '17 at 15:14

I broke your algorithm into two frames...

Here is the code:

\documentclass[11pt]{beamer}% http://ctan.org/pkg/beamer
\mode<presentation>

\usepackage{float}

\usepackage{algpseudocode,algorithm,algorithmicx}
\usepackage{algcompatible}
\setbeamertemplate{frametitle}[default][center]

\usepackage{caption}

\usepackage{xkeyval}

\usepackage{etoolbox}
\usepackage{ragged2e}
\apptocmd{\frame}{}{\justifying}{} % Allow optional arguments after frame.

\setbeamertemplate{caption}[numbered]

\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry location}{}
\setbeamertemplate{bibliography entry note}{}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{epstopdf}

\begin{document}

\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}
%\framesubtitle{\centerline{frame subtitle}}

\begin{algorithm}[H]
\caption{Pseudocode for the GWO}
\label{gwo}
\begin{algorithmic}[1]
%   \Procedure{Hybrid BAT-Genetic Algorithm}{}
\\Input :Grey wolf population:$X_{i}(i = 1, 2, ..., n)$,Maximum Number of iteration:Max\_it
\\Output :$X_{a}$ : Optimal Position(Optimized filter coefficients)
\\Objective function : PSNR
\hrule
\\Initialize the Grey wolf population $X_{i} = (i=1,2, ...,n)$
\\Initialize the coefficient vectors a, A, and C
\State $\vec{A}=2\vec{a}\vec{r_1}-\vec{a}$
\State $\vec{C}=2\vec{r_2}$
\Comment where components of are linearly decreased from 2 to 0 over the course of iterations and,\\ are random vectors in $[0,1]$
\For{all $X_{i}$}
\State Calculate fitness $F(X_{i})$ of all $X_{i}$
\EndFor
\algstore{myalg}
\end{algorithmic}
\end{algorithm}
\end{frame}

\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}

\begin{algorithm}[H]
\ContinuedFloat
%     \caption{Pseudocode for the GWO}
\begin{algorithmic}[1]
\algrestore{myalg}
\State Rank the gray wolf in descending order based on the fitness
\State $X_{\alpha}$ = the first search agent
\State $X_{\beta}$ = the second search agent
\State $X_{\delta}$ = the third search agent
\State t=1;
\While{t\textless Max\_it}
\For{i=1:n}
\State Update the position of the current search agent \mbox{$\vec{F}(t+1) = \frac{\vec{F_{1}}+\vec{F_{2}}+\vec{F_{3}}}{3}$}
\EndFor
\State Update $a$,$A$, and $C$
\For{all $X_{i}$}
\State Calculate fitness $F(X_{i})$ of all $X_{i}$
\EndFor
\State Update $X_{\alpha}$, $X_{\beta}$, and $X_{\delta}$
\State t=t+1;
\EndWhile
\State Return the first best agent $X_{\alpha}$ found so far
\\Post-processing the results and visualization
%   \EndProcedure
\end{algorithmic}
\end{algorithm}

\end{frame}

\end{document}