0

I am using the algorithm2e package to write algorithms. I have three algorithms that I want to put in a single page. I tried using subfigures and minipages but it got me no where. Any help to get me started is appreciated. Thank you.

Werner
  • 603,163
Zaza
  • 1

2 Answers2

1

You may only have 2 algorithms appearing on a page because of the default settings for floats in LaTeX. If you want more floats on a page, follow the guidance listed in How can I adjust the number of figures LaTeX will display on a page.

Another option is to put them all in the same float (say, a figure) and then use the [H]ere option to make the algorithms not float.

enter image description here

\documentclass{article}

\usepackage[ruled]{algorithm2e} \SetKwInput{Input}{Input} \SetKwInput{Output}{Output}

\begin{document}

Here is some text.

\begin{figure} \begin{algorithm}[H] \caption{First algorithm} \Input{input A} \Output{output A} A statement; \end{algorithm}

\vspace{\floatsep}

\begin{algorithm}[H] \caption{Second algorithm} \Input{input B} \Output{output B} A statement; \end{algorithm}

\vspace{\floatsep}

\begin{algorithm}[H] \caption{Third algorithm} \Input{input C} \Output{output C} A statement; \end{algorithm} \end{figure}

Here is some more later in the document.

\end{document}

Werner
  • 603,163
1

Just for fun:

\documentclass{article}

\usepackage[ruled]{algorithm2e} \SetKwInput{Input}{Input} \SetKwInput{Output}{Output}

\usepackage{paracol} \globalcounter{algocf}

\begin{document}

Here is some text.

\begin{paracol}{3} \begin{algorithm} \caption{First algorithm} \Input{input A} \Output{output A} A statement; \end{algorithm} \switchcolumn \begin{algorithm} \caption{Second algorithm} \Input{input B} \Output{output B} A statement; \end{algorithm} \switchcolumn \begin{algorithm} \caption{Third algorithm} \Input{input C} \Output{output C} A statement; \end{algorithm} \end{paracol}

Here is some more later in the document.

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120