LaTeX中实现算法的呈现主要有两种方式:
使用宏包
algorithm2e
, 这个宏包有很多可选项进行设定。使用宏包
algorithm
与algorithmic
, 好像挺多人喜欢用,周志华老师的<<机器学习>>一书中的算法描述应该就是使用的这两个宏包。
使用宏包algorithm2e
:
\usepackage[linesnumbered,boxed,ruled,commentsnumbered]{algorithm2e}%%算法包,注意设置所需可选项
\IncMargin{
1em} % 使得行号不向外突出
\begin{
algorithm}
\SetAlgoNoLine % 不要算法中的竖线
\SetKwInOut{
Input}{
\textbf{
输入}}\SetKwInOut{
Output}{
\textbf{
输出}} % 替换关键词
\Input{
\\
The observed user-item pair set $S$\;\\
The feature matrix of items $F$\;\\
The content features entities $A := \{
A^u,A^v\}$\;\\}
\Output{
\\
$