# How to compress algorithm in a beamer presentation?

I have written one algorithm in a beamer class by using a package \usepackage[linesnumbered, ruled,vlined]{algorithm2e}. It is taking the whole slide, I have tried to fit it into a small minpage but it is not working.

Is there any way to compress an algorithm in a beamer class. I can't share my algorithm.

\documentclass{beamer}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{caption}
\usepackage{xcolor}
\usepackage{array}
\begin{document}

\date{\today}

\frame{\titlepage}

\section{Section no.1}
\frame{\frametitle{dwd}

\begin{center}
\begin{minipage}{1\linewidth}
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} : A graph $(G)$\;
\textbf{Decide} : Is $G$ a random ? \\
\vspace{0.3cm}

If $X$ then stop and play and dance random \;
$S = \{g \in G \}$\;
Pick sdy $g \in P$\;
Find n elemen. If  exits  then returno   Not sonian ''\;

\If{$X$}{
Compute a lower and upper $L$ of $X$ in $G$;\\

\If{$X$ exists and is fumbling lelal -grou}{

return $zZ$\;
}
}

\Else{
return  Not truein life''\;
}

\caption{Algorithm}
\label{algofinite}
\end{algorithm}
\end{minipage}
\end{center}

}

\end{document}

• 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 Jan 17 at 16:40
• I will not able to share more of my code sorry. – Isla_Bonita Jan 17 at 16:48
• The content of your algorithm does not matter, you could just make up some random algorithm that demonstrates your problem. The important point is to show use a small but compilable latex document that allows us to reproduce your problem. – user36296 Jan 17 at 16:52

I suggest to use a smaller fonts size to fit the algorithm into the frame. If \small is not enough and you are really desperate, try \foototesize, \scriptsize, \tiny or \Tiny

• you don't need to load the xcolor package with beamer

• remove the center environment. It has no effect on content that spans over the whole text width, like your algorithm and just adds even more vertical spacing around which makes your problem worse

• instead of \frame{} better use the \begin{frame}....\end{frame} syntax

\documentclass{beamer}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{caption}
%\usepackage{xcolor}
\usepackage{array}
\begin{document}

%\date{\today}

\begin{frame}
\frametitle{dwd}

\begingroup
\small
%\begin{center}
%\begin{minipage}{1\linewidth}
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} : A graph $(G)$\;
\textbf{Decide} : Is $G$ a random ? \\
\vspace{0.3cm}

If $X$ then stop and play and dance random \;
$S = \{g \in G \}$\;
Pick sdy $g \in P$\;
Find n elemen. If  exits  then report   Not sonian ''\;

\If{$X$}{
Compute a lower and upper $L$ of $X$ in $G$;\\

\If{$X$ exists and is fumbling lelal -grou}{

return $zZ$\;
}
}

\Else{
return  Not truein life''\;
}

\caption{Algorithm}
\label{algo6}
\end{algorithm}
%\end{minipage}
%\end{center}
\endgroup

\end{frame}

\end{document} 