12

I can't seem to figure out how to place a caption at the beginning of an algorithm2e pseudo code. I know it's possible with the ruled environment, but I don't want those lines at the top and the bottom. How can I move the algorithm caption above the code?

1 Answer 1

19

You could adjust the way the plain (default) style sets the caption (from bottom to above or top):

enter image description here

\documentclass{article}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
\makeatletter
\renewcommand{\@algocf@capt@plain}{above}% formerly {bottom}
\makeatother
\begin{document}

\begin{algorithm}[H]
  \SetAlgoLined
  \KwData{this text}
  \KwResult{how to write algorithm with \LaTeX2e }
  initialization\;
  \While{not at end of this document}{
    read current\;
    \eIf{understand}{
      go to next section\;
      current section becomes this one\;
    }{
      go back to the beginning of current section\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm}

\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .