答案1
- 为了获得多级缩进,我建议使用
enumitem
包:定义一种没有项目符号的新类型的列表(例如level
),因此只提供可以嵌套的缩进。 - 要获取用户定义的引用,您需要定义一个计数器(例如
algo
)并\refstepcounter
在您希望引用指向的位置调用。
我将这两件事(连同水平线)结合起来,定义了一个新环境àlgorithm
:
\documentclass{article}
\usepackage{hyperref}
\usepackage{enumitem}
\newlist{level}{itemize}{4}
\setlist[level]{label={},noitemsep,topsep=0pt}
\newcounter{algo}
\renewcommand{\thealgo}{\arabic{algo}.}
\newenvironment{algorithm}[1]{%
\refstepcounter{algo}%
\paragraph{Algorithm \thealgo}#1%
\vspace{2pt}\hrule\vspace{5pt}%
\begin{level}
}{%
\end{level}%
\vspace{5pt}\hrule\vspace{\baselineskip}%
}
\begin{document}
We summarize the PF-EKF in Algorithm~\ref{algo:ekf}
\begin{algorithm}{Particle filter with EKF proposal}\label{algo:ekf}
\item \textbf{Initialize:}
\item Draw the particles by using $\{x_0^f\}_{i=1}^M\!\sim\!p(x_0)$
\item \textbf{for} k=1 to N \textbf{do}
\begin{level}
\item \textbf{Prediction Step:}
\item Draw the particles by using the Equation 52
\item \textbf{Measurement Step:}
\item Update the weight by using the Equation 56
\item \textbf{Resample Step}
\end{level}
\item end for
\end{algorithm}
\end{document}