2

I don't want to use ruled option, but still, I want the caption of my algorithm to be at the upper left corner.

I tried

\renewcommand{\@algocf@capt@plain}{above}

but it only moves the caption above, not on the left.

Example output:

enter image description here

When I use \TitleOfAlgo, the line Algorithm 1 is numbered.

1 Answer 1

3

With the ruled option, the horizontal rules above/below the entire algorithm block is set with a height of \algoheightrule, while the rule between the caption and the algorithm is set with a height of \algotitleheightrule. Setting these to 0pt removes the rules, yet keeps the same ruled-like format:

enter image description here

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

\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}

\setlength{\algoheightrule}{0pt}
\setlength{\algotitleheightrule}{0pt}

\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}

You must log in to answer this question.

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