Side-by-side algorithms in two columns paper

I am trying to put two algorithms side-by-side on a page so it is easy to compare their differences. I am using the acm template, algorithm2e package and minipage environment. but I get this error:

! LaTeX Error: [H] in two columns mode is not allowed for algorithms.


I have followed these steps in this post, but it dose not work out for me. multiple algorithm2e algorithms in two column documents

Does anyone know how I can put two algorithms side-by-side?

This is my sample code it us work fine in one column page but it does not work in two column page.

\begin{minipage}[t]{8cm}

\null
\begin{algorithm}[H]
% \caption{Algo 1}

\SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{Generation step}\SetKwInOut{Output}{Initialization step}
\Input{\color{blue} Generate }
\Output{ $K$}
\BlankLine
\Output{\color{blue}***,**}

\emph{\bf{\color{blue} 444}}\;
\emph{\color{blue} 2222}\;
\emph{\color{blue}11111\;}
\emph{\color{blue}111\;}
\emph{###\;
}
\BlankLine
\emph{\bf{\color{blue} Received $ID$}}\;
\For{\color {blue} each node that receives a ID}{
\If{\color {blue} ##}{\color {blue} Add value to the list
}
\BlankLine
\For{Each $received ID$}{
Find *,$s$\;
\eIf{$s$ $>$ ID$}{do nothing}{Replace #} } } \BlankLine Find the smallest element on the list,$s$\; \eIf{$s=0$}{###}{*** }\BlankLine \BlankLine \caption{DNE Algorithm}\label{DNE Algorithm} \end{algorithm} \end{minipage}% \removelatexerror \begin{minipage}[t]{8cm} \null \begin{algorithm}[H] \emph{**}\; % \Output{***} \emph{**}\; \emph{** size to 1}\; \BlankLine \emph{\bf{Broadcast}}\; \emph{broadcast it}\; \BlankLine \emph{\bf{Estimation}}\; \For{each ID$}{
Find the smallest ,$s$\;
\eIf{$s$ $>$ $received ID$}{do nothing}{Replace $s$ }
}
\BlankLine
Find the smallest element on the list, $s$\;
\eIf{$s$ $=$ $0$}{1111}{ab}\BlankLine
\caption{Algorithm}\label{DNE-Algorithm}

\end{algorithm}
\end{minipage}

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Sep 26 '14 at 10:41
• Have you tried tex.stackexchange.com/a/147918/17423? – Sean Allred Sep 26 '14 at 12:27
• Two-column floats are typeset only on the top of the page by default. Use one single float and two minipages in it. – Johannes_B Sep 26 '14 at 12:28
• Thanks, but how can I use it. I am new in latex. do you have a sample code? – user3593321 Sep 26 '14 at 12:45
• @SeanAllred yes, I got the same error with this style. – user3593321 Sep 26 '14 at 13:04

Package algorithm2e does not allow H in twocolumn mode, regardless if single or double float. A little excerpt from the package file:

\if@twocolumn\@latex@error{[H] in two columns mode is not allowed for algorithms}\fi% TODO: SCREAM if H in two colums!

Bad thing is, for some reason two captions in an algorithm environment don't work. The solution can be a quick hack, using a figure and mimicking and algorithm. You have to be very careful with the order of your algorithms that way. There is a pretty high chance, that the numbering gets messed up.
There might be a much better and cleaner solution.

\documentclass[twocolumn
]{article}
\usepackage{blindtext}
\usepackage{algorithm2e}
\begin{document}
\blindtext[5]
\begin{algorithm*}%[H]
\begin{minipage}{0.45\textwidth}
\rule{\linewidth}{2cm}
\caption{left side of a pretty pretty long long
long very very long caption}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\rule{\linewidth}{4cm}
\caption{right side of a pretty pretty long long
long very very long caption}
\end{minipage}
\end{algorithm*}

\blindtext
\begin{figure*}
\makeatletter
\def\@captype{algocf}
\makeatother
\begin{minipage}{0.45\textwidth}
\rule{.5\linewidth}{2cm}
\caption{left side of a pretty pretty long long
long very very long caption}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\rule{\linewidth}{4cm}
\caption{right side}
\end{minipage}
\end{figure*}
\blindtext[5]
\end{document}

• Thanks for your help, but it dose not work out, because algorithm 1 is written after algorithm 2. but I want them side by side. – user3593321 Sep 29 '14 at 12:41
• @user3593321 Does that happen with the above minimal example copied pasted and compiled? – Johannes_B Sep 29 '14 at 17:15
• I could managed it. I followed this example and it ś working for me.tex.stackexchange.com/questions/116629/… – user3593321 Sep 30 '14 at 6:39