latex 伪代码:【转载】

原文:http://blog.sina.com.cn/s/blog_5e16f1770100lp7u.html
1.首先添加如下内容:
\usepackage[linesnumbered,boxed]{algorithm2e}
2.然后正文中添加如下示例:
\begin{algorithm}
\caption{identifyRowContext}
\KwIn{$r_i$ , $Backgrd(T_i)$=${T_1,T_2,\ldots,T_n}$ and similarity
threshold $\theta_r$}
\KwOut{$con(r_i)$}
$con(r_i)= \Phi$\;
\For{$j=1;j \le n;j \ne i$}
{
$con(r_i)=con(r_i) \cup {r^{maxSim}}$\;
}
return $con(r_i)$\;
\end{algorithm}
3.效果运行可知。
http://s10/middle/5e16f177h91109650f1e9&690
扩展:
一、如何修改算法的标题为中文“算法”?
\renewcommand{\algorithmcfname}{算法} 即可
二、如何去掉算法中的竖线?
\SetAlgoNoLine 放在算法中即可。
三、若是使用其他标题样式,可以使用:
\usepackage[ruled,vlined]{algorithm2e}
这些默认参数来定制标题,caption宏包并不能对其进行修改。其他样式
参看:http://mirror.bjtu.edu.cn/CTAN/macros/latex/contrib/algorithm2e/algorithm2e.pdf