Latex对伪代码标题按照章节进行编号,插入语句
\counterwithin{algorithm}{chapter}
即可。
这里以一个点云降采样FPS算法为例子。算法可参考:https://blog.csdn.net/QFJIZHI/article/details/103419044
\begin{algorithm}
\counterwithin{algorithm}{chapter}
\caption{FPS Algorithms}
\begin{algorithmic}[1]
\Require Pint set $P$, number of iterations $n$.
\State Initialize new point set $P'$
\State $p_0 \leftarrow$ Random picked initial point from $P$.
\State Insert $p_0$ into $P'$.
\For{$i = 1,...,n$}
\State $p_i \leftarrow$ NULL, $d_i \leftarrow$ 0.
\For{$p_j$ in $P$}
\State $d_j$ = min $\left\|p_j - P'\right\|_2\ \leftarrow$ Distance from point $p_j$ to point set $P'$.
\If{$d_j > d_i$}
\State $p_i \leftarrow p_j$, $d_i \leftarrow d_j$.
\EndIf
\EndFor
\State Insert $p_i$ into $P'$.
\EndFor
\State \Return{$P'$}
\end{algorithmic}
\end{algorithm}
输出结果:
可以看到算法后面的编号变成了2.1,而不是原来的1,2,3,4了。完美。