latex插入伪代码

分类: tex |
方法一:
需要宏包:
常用命令:
\Procname
\li \zi: 换行, \zi不编号
\End 可以结束 \For \While if-then if-then-else 语句
例子:
\begin{codebox}
\Procname{$\proc{Insertion-Sort(A)}$}
\li \For $j \gets 2$ \To
$\id{length}[A]$
\li
\li
\li
\li
\li
\li
\li
\end{codebox}
http://s6/mw690/001t3Vlyzy6IlLcqZMhf5&690
方法二:
需要宏包:
\usepackage{caption}
\usepackage{algorithm}
\usepackage{algpseudocode}
另外:
1. \usepackage[noend]{algorithm},\usepackage[noend]{algpseudocode}中的noend选项,可以使算法显示中看不到endif,end等字眼。更节省空间。
2.[boxed]可以使算法外围加一个大框。
基本命令:
\State
\If{}
\If{}
\If{}
\For{}
\ForAll{}
\While{}
\Repeat
\Loop
\Require
\Ensure
\Function{}{}
\State
\Return
\Comment{}
网上的两个例子:
\documentclass{article}
\usepackage{caption}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\end{algorithm}
\end{algorithm}
注:公式内的空格用“~~” 如:$\alpha \gets i~~i\in(0,1)$