可以在伪代码环境中使用\setcounter{AlgoLine}{1}命令将行数计数器重置为1。下面是一个例子:

\begin{algorithm}
  \setcounter{AlgoLine}{1}
  \caption{My algorithm}
  \begin{algorithmic}[1]
    \State $x \gets 0$
    \State $y \gets 1$
    \For{$i \gets 1$ to $n$}
      \State $z \gets x + y$
      \State $x \gets y$
      \State $y \gets z$
      \State print $z$
    \EndFor
  \end{algorithmic}
\end{algorithm}

在这个例子中,我们在算法环境中使用了\setcounter{AlgoLine}{1}命令来将计数器重置为1。这意味着第一行将从1开始计数,而不是默认的0。

LaTeX 伪代码:如何从 1 开始重新显示行号

原文地址: https://www.cveoy.top/t/topic/nSLw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录