代码上方的 Algorithm2e 标题

代码上方的 Algorithm2e 标题

我似乎不知道如何在algorithm2e伪代码的开头放置标题。我知道在环境中可以做到这一点ruled,但我不想在顶部和底部放置这些行。如何将算法标题移到代码上方?

答案1

plain您可以调整(默认)样式设置标题的方式(从bottomabovetop):

在此处输入图片描述

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

相关内容