I'd like to use similar styles for pseudocode/algorithms and listings using the algorithm2e
package. Therefore I need a line above and below the algorithm but not above the caption. Haven't found any solution so far.
Adjusted several configurations like the style of the line numbers and the caption, but yeah.. cannot getting rid off the line above:
\setlength{\algoheightrule}{0.4pt}
\renewcommand\AlCapFnt{\normalfont}
\SetAlgoCaptionLayout{centerline}
\SetNlSty{ttfamily}{}{}
\SetAlgoNlRelativeSize{-3}
Thanks a lot!
MWE:
\documentclass[a4paper, 11pt]{book}
\usepackage[ruled]{algorithm2e}
\begin{document}
\begin{algorithm}
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX}
\caption{How to write algorithms}
\end{algorithm}
\end{document}
Best Answer
You can set the algorithms using the
plainruled
style - two single rules, one above, one below the algorithm - and adjust the way the algorithm caption is set; default isunder
, so we change that toabove
(nottop
):A minor adjustment is included to add a space between the caption and the algorithm's top rule.