[Tex/LaTex] Caption below boxed algorithm2e when used as a figure

algorithm2ecaptionsfloats

My desired output is similar to the example given in this answer, in that I want the caption below the algorithm and outside the box, except I want the algorithm included as a figure (so I use \usepackage[figure,boxed]{algorithm2e}).

Currently I have something like this:

enter image description here

The MWE:

\documentclass[a4paper]{article}

\usepackage{blindtext}
\usepackage[linesnumbered,boxed,figure]{algorithm2e}

\SetAlCapSkip{1em}

\SetKwInput{KwInput}{Input}
\SetKwInput{KwOutput}{Output}

\begin{document}

  \begin{algorithm}[h]
    \SetAlgoLined
    \KwInput{Parameters...}

    \KwOutput{$\emptyset$}

    \If{Condition}
    {
      Do something \;
    }
    \caption{Algoritm test...}
  \end{algorithm}


\end{document} 

Best Answer

One way to go is to set the algorithm as a non-floating object (use H instead of h) and use a normal figure environment instead of the option figure when loading algorithm2e.

MWE:

\documentclass[a4paper]{article}

\usepackage{blindtext}
\usepackage[linesnumbered,boxed]{algorithm2e}

%\SetAlCapSkip{1em}

\SetKwInput{KwInput}{Input}
\SetKwInput{KwOutput}{Output}

\begin{document}

\begin{figure}[h]
  \begin{algorithm}[H]
    \SetAlgoLined
    \KwInput{Parameters...}

    \KwOutput{$\emptyset$}

    \If{Condition}
    {
      Do something \;
    }
  \end{algorithm}
  \caption{Algoritm test...}
\end{figure}

\end{document} 

Output:

enter image description here

Related Question