概要
texによくあるalgorithmの使い方まとめ
下記のように、\begin{algorithm}
の中に\begin{algorithmic}
をいれて、その中に任意のアルゴリズムを記述します。
\begin{algorithm}
\caption{Title}
\begin{algorithmic}
ここにアルゴリズムを書く
\end{algorithmic}
\end{algorithm}
基本操作
初期化(Initialize:を定義する)
\begin{document}
の前に定義しておく。
\algnewcommand{\Initialization}[1]{%
\State \textbf{Initialization:}
\State \hspace*{\algorithmicindent}\parbox[t]{0.8\linewidth}{\raggedright #1}
}
\Initialization{
$x$ := $0$
$y$ := \Call{GetValue}{$x$}
}
for all
\ForAll{$value\in values$}
\State \Call {PRINT}{$value$}
\EndFor
if/else if/else
\Function{CheckNumber}{$x$}
\If{$x > 10$}
\State \Call {PRINT}{$``xは10より大きい"$}
\ElsIf{$x >= 5$}
\State \Call {PRINT}{$``xは5以上10以下"$}
\Else
\State \Call {PRINT}{$``xは5未満"$}
おまけ
文字列等でダブルクォーテーションを使いたい時
``文字列"
参考
http://li-feel.hatenablog.com/entry/2017/12/19/160618
https://github.com/PMOB/study-tex/wiki/reference-algorithm