0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

tex algorithm 記述方法

Last updated at Posted at 2020-12-30

概要

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$}
  }

スクリーンショット 2020-12-30 123650.png

for all

\ForAll{$value\in values$} 
  \State \Call {PRINT}{$value$}
\EndFor

スクリーンショット 2020-12-30 123708.png

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未満"$}

スクリーンショット 2020-12-30 124340.png

おまけ

文字列等でダブルクォーテーションを使いたい時


``文字列"

参考

http://li-feel.hatenablog.com/entry/2017/12/19/160618
https://github.com/PMOB/study-tex/wiki/reference-algorithm

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?