【插件筆記】關於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 的中文操作

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章