關於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 的中文操作