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:

 % my algorithm here

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:



\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
\While{not at end of this document}{
read current\;
go to next section\;
current section becomes this one\;
go back to the beginning of current section\;
\caption{How to write algorithms}
  • You can possibly use minipage, as they do it in this post
    – RockyRock
    Commented May 29, 2018 at 4:17
  • 1
    It is good practice to provide a MWE so we can see what the problem really is
    – RockyRock
    Commented May 29, 2018 at 4:24
  • It is probably too late, but an algorithm must not be placed inside a figure environment
    – BambOo
    Commented May 18, 2020 at 20:30


You must log in to answer this question.

Browse other questions tagged .