I tried this example Place four algorithms (algorithm2e) in a subfigure and arrange them in two rows and two columns on two column documents. It doesn't work. The error message is

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

Is there anyway to go?

The code example is:


\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}
    \end{subfigure}% need this comment symbol to avoid overfull hbox
        \caption{How to write algorithms}
        \caption{How to write algorithms}
        \caption{How to write algorithms}
\caption{Main caption}


2 Answers 2


algorithm2e provides its own [H] float parameter, which sidesteps setting its contents as a float. However, in twocolumn mode, it produces an error. I'm not sure why. You can avoid this by setting \@latex@error to \@gobble temporarily. Using your example, I've added a \removelatexerror macro inside a \begingroup...\endgroup. More specifically, the definition


is placed inside a group, inside \myalgorithm:

\removelatexerror% Nullify \@latex@error

Also, since you're spreading the 4 algorithms across both columns, it's best to use figure* rather than figure:

enter image description here

Obviously you won't be using \myalgorithm in your actual document. You could just place \removelatexerror inside each of the subfigure environments.


I had similar issues...

I simply removed [H] from the code as below.




Then the issue solved.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.