# Two algorithm2e environments side by side

I want to get two algorithm2e environments side by side aligned at the top. I tried it with two minipages, but it does not work. How do I get them side by side in the normal text (not in a floating environment)?

Here is a MWE:

\documentclass{article}
\usepackage[ruled,noend]{algorithm2e}
\begin{document}

\begin{minipage}{5cm}
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
line 2\;
\end{algorithm}
\end{minipage}%
\begin{minipage}{5cm}
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
\end{algorithm}
\end{minipage}

\end{document}

• Add \vspace{0pt} at the beginning of each minipage environment. Related to tex.stackexchange.com/questions/11630/… – jub0bs Dec 1 '13 at 21:42
• That doesn't work for me. ...\begin{minipage}{5cm} \vspace{0pt}\begin{algorithm}[H]... – Ivo Dec 1 '13 at 21:45

## 2 Answers

You need the [t] flag and the magic '\vspace{0pt}:

\documentclass{article}
\usepackage[ruled,noend]{algorithm2e}
\begin{document}

\begin{minipage}[t]{5cm}
\vspace{0pt}
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
line 2\;
\end{algorithm}
\end{minipage}%
\begin{minipage}[t]{5cm}
\vspace{0pt}
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
\end{algorithm}
\end{minipage}

\end{document}

• This also adds a blank line (or a vertical space of a line) at the top of the minipage (before the minipage). – Ivo Dec 1 '13 at 22:04
• @Ivo Then make the vspaces negative. There is no text before the algorithms in your question, so we didn't know. – Alex Dec 1 '13 at 22:11

A bit different approach:

\documentclass{article}
\usepackage[ruled,noend]{algorithm2e}

\begin{document}

\begin{minipage}[t]{5cm}
\null
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
line 2\;
\end{algorithm}
\end{minipage}%
\begin{minipage}[t]{5cm}
\null
\begin{algorithm}[H]
\caption{Algo 1}
line 1\;
\end{algorithm}
\end{minipage}

\end{document}


• This adds a blank line (or a vertical space of a line) at the top of the minipage (before the minipage). – Ivo Dec 1 '13 at 22:00