# How to resize an algorithm to fit into one page

I am using algorithm2e for writing an algorithm. I have a long algorithm that exceeds one A4 page length. But I want to compress it to fit into one page (resize percentage).

I tried \resizebox but did not work. I get this error:

Error: LaTeX Error: Not in outer par mode.
Error: Undefined control sequence.
Error: Missing number, treated as zero


Here is my latex structure:

\resizebox{0.8\textwidth}{!}
{
\begin{algorithm*}
% my algorithm here
\end{algorithm*}
}


EDIT: I tried \resizebox, \minipage, and here \figure which gives this error:

Nothing works. All what I need is to scale (resize so that the whole algorithm fits in one page). Otherwise, my actual algorithm is long and gets chopped at the end of the page and does not even continue in another page.

Here is an example (my actual algorithm is long but the problem is demonstrated here):

The error is:

Error: LaTeX Error: Not in outer par mode.


The script:

\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithm2e}

\begin{document}

\begin{figure}
\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{figure}
\end{document}

• You can possibly use minipage, as they do it in this post – RockyRock May 29 '18 at 4:17
• It is good practice to provide a MWE so we can see what the problem really is – RockyRock May 29 '18 at 4:24