关于latex写algorithm的一点笔记
algorithm2e包
\usepackage[ruled]{algorithm2e}
\begin{algorithm}[H]
\caption{algorithm caption}%算法名字
\LinesNumbered %要求显示行号
\KwIn{input parameters A, B, C}%输入参数
\KwOut{output result}%输出
some description\; %\;用于换行
\For{condition}{
only if\;
\If{condition}{
1\;
}
}
\While{not at end of this document}{
if and else\;
\eIf{condition}{
1\;
}{
2\;
}
}
\ForEach{condition}{
\If{condition}{
1\;
}
}
\end{algorithm}
结果图如下:
用
\usepackage[ruled,vlined]{algorithm2e}
结果是
如果想在algorithm2e里用do-while而不是Repeat-Until
\SetKwRepeat{Do}{do}{while}
重设关键字就可以使用如下语法
\Do{<end condition>}{<stuff>}
如果想在overleaf里用中文
\usepackage[UTF8]{ctex}
然后更改overleaf 编译引擎 为 XeLaTex
黑体:\heiti
楷书:\kaishu
参考
LaTeX算法排版
do-while loop in algorithm2e
LaTeX学习系列之—Latex 的中文操作