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$}
{
 float $maxSim=0$\;
 $r^{maxSim}=null$\;
  \While{not end of $T_j$}
 {
     compute Jaro($r_i,r_m$)($r_m \in T_j$)\;
     \If{$(Jaro(r_i,r_m) \ge \theta _r) \wedge ((Jaro(r_i,r_m) \ge r^{maxSim}) $}
      {
           replace $r^maxSim$ with $r_m$\;
      }   
 }
$con(r_i)=con(r_i) \cup {r^{maxSim}}$\;
}
return $con(r_i)$\;
\end{algorithm}

3.效果运行可知

LaTex 带边框逻辑清晰的伪代码_第1张图片

扩展:
一、如何修改算法的标题为中文“算法”?
\renewcommand{\algorithmcfname}{算法} 即可
二、如何去掉算法中的竖线?
\SetAlgoNoLine 放在算法中即可。
三、若是使用其他标题样式,可以使用:
\usepackage[ruled,vlined]{algorithm2e}
这些默认参数来定制标题,caption宏包并不能对其进行修改。其他样式
参看:http://mirror.bjtu.edu.cn/CTAN/macros/latex/contrib/algorithm2e/algorithm2e.pdf


第二种方式:

\documentclass{article}
\usepackage[ruled]{algorithm2e}
 
\begin{document}
\begin{algorithm}[H]
\caption{How to write algorithms}
\KwIn{this text}
\KwOut{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
    read current\;
    \eIf{understand}{
        go to next section\;
        current section becomes this one\;
    }{
        go back to the beginning of current section\;
    }
}
\end{algorithm}
\end{document}

LaTex 带边框逻辑清晰的伪代码_第2张图片

你可能感兴趣的:(Latex)