![algorithm2e 的标题位于左上角,无规则选项](https://linux22.com/image/292878/algorithm2e%20%E7%9A%84%E6%A0%87%E9%A2%98%E4%BD%8D%E4%BA%8E%E5%B7%A6%E4%B8%8A%E8%A7%92%EF%BC%8C%E6%97%A0%E8%A7%84%E5%88%99%E9%80%89%E9%A1%B9.png)
我不想使用ruled
选项,但我仍然希望我的算法的标题位于左上角。
我试过
\renewcommand{\@algocf@capt@plain}{above}
但它只会移动上面的标题,而不是左边的标题。
示例输出:
当我使用时\TitleOfAlgo
,该行算法 1已编号。
答案1
使用此ruled
选项,整个算法块上方/下方的水平规则的高度为\algoheightrule
,而标题和算法之间的规则的高度为\algotitleheightrule
。 将这些设置为0pt
会删除规则,但仍保持相同的ruled
类似格式:
\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}