最近写报告要插入个algorithm格式,然后查了下latex的相关文档,这里做下记录。
latex的与algorithm相关的包常用的有几个,algorithm
、algorithmic
、algorithmicx
、algorithm2e
,可以大致分成三类,或者说三个排版环境。最原始的是使用algorithm
+algorithmic
,这个最早出现,也是最难用的,需要自己定义一些指令。第二个排版环境是algorithm
+algorithmicx
,algorithmicx
提供了一些宏定义和一些预定义好了的环境(layout),指令类似algorithmic
。第三个是algorithm2e
,只需要一个包,使用起来和编程的感觉很像,也是我更倾向使用的包。下面是使用algorithm2e
的例子。[1]
\documentclass[a4paper]{ctexart}
\usepackage[ruled]{algorithm2e}
% some others
\begin{document}
% some others
\begin{algorithm}
%\SetAlgoRefName{} % no count number
\caption{pISTA}
\label{alg:pISTA}
Parameters: $\lambda, \gamma$\;
Initialization: $x_0$\;
\While{not converge}{
$x_{k+1}=\Psi^*T_{\lambda\gamma}(\Psi(x_k+\gamma \mathcal{F}^{-1}Q_p(y-Q_p \mathcal{F}x_k)))$\;
}
\end{algorithm}
\end{document}
这里简单解释下,ruled表示显示algorithm环境的上下两条线,这个可以试下去掉和不去掉的区别。下面的\SetAlgoRefName{}
表示不显示标题(caption)的Algorithm编号,也就是说将原来的Algorithm n:
变成Algorithm:
,之所以用这个是因为写的报告不想要这个编号[2],更多的使用说明,可以直接查阅官方文档,感觉更细节点。这个算法来自最近看的一篇文章[3],关于MRI的分析模型求解算法,感觉Introduction和Background讲的很不错,感兴趣的可以看看。
-
更多关于这三种algorithm排版环境的说明. https://tex.stackexchange.com/questions/229355/algorithm-algorithmic-algorithmicx-algorithm2e-algpseudocode-confused# ↩
-
官方文档
algorithm2e.pdf
,9.2.1节,"And if you want to name your algorithm and not number it, you can change the reference of it by using \SetAlgoRefName{ref}" ↩ -
Liu Y, Zhan Z, Cai J F, et al. Projected Iterative Soft-thresholding Algorithm for Tight Frames in Compressed Sensing Magnetic Resonance Imaging[J]. 2015. ↩