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.
-
I tried with vbox and it does seem to work but thank you for looking into this. – Zaza Sep 07 '21 at 03:30
2 Answers
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.
\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}
- 603,163
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}
- 79,712
- 3
- 50
- 120

