我在 Overleaf 中使用 IEEEtran 模板。我在 Overleaf 中编写算法。
但是,它在算法的左侧添加了一系列不需要的零,并且=0
在最后一行也添加了一个不需要的零,这也是我的代码,
\begin{algorithm}
\caption{Migration algorithm}
\begin{algorithmic}
\label{alg:migration}
\For {$iteration=1,2,\ldots$,N}
\For {$episodes=1,2,\ldots,M$}
\State $R_b \leftarrow 0$
\State $R_l \leftarrow 0$
\For {$timesteps=1,2,\ldots,T$}
\State Run a trajectory $\pi_{\theta_{old/new}}$ for $T$ timesteps
\State Compute the timestep latency reward $r_l$
\State Compute the timestep binpacking reward $r_b$
\EndFor
\State $R_b \leftarrow R_b + r_b$
\State $R_l \leftarrow R_l + r_l$
\EndFor
\State $R \leftarrow w_1 R_b + w_2 R_l$
\State Optimize the RL Agent policy $\pi$ based on R
\State Move the containers based on $\pi$
\EndFor
\end{algorithmic}
\end{algorithm}
这些也是与我正在使用的算法相关的包的列表。
\usepackage{algorithmic}[1]
\usepackage{algpseudocode}
\usepackage{algorithm}
我想要的是算法的行号而不是零,而且最后我也不想要该end for=0
部分。
答案1
(这个答案建立在之前的评论之上)
我建议你(a)不是加载algorithmic
包并(b)更改\begin{algorithmic}
为\begin{algorithmic}[1]
启用行号。
\documentclass{IEEEtran}
\usepackage{amsmath,newtxtext,newtxmath}
%\usepackage{algorithmic}[1] % <-- don't load this package
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{Migration algorithm} \label{alg:migration}
\begin{algorithmic}[1] % <-- added '[1]' to control line numbering
\For {$\textrm{iteration}=1,2,\ldots,N$}
\For {$\textrm{episodes}=1,2,\ldots,M$}
\State $R_b \leftarrow 0$
\State $R_l \leftarrow 0$
\For {$\textrm{timesteps}=1,2,\ldots,T$}
\State Run a trajectory $\pi_{\theta_{\textrm{old/new}}}$ for $T$ timesteps
\State Compute the timestep latency reward $r_l$
\State Compute the timestep binpacking reward $r_b$
\EndFor
\State $R_b \leftarrow R_b + r_b$
\State $R_l \leftarrow R_l + r_l$
\EndFor
\State $R \leftarrow w_1 R_b + w_2 R_l$
\State Optimize the RL Agent policy $\pi$ based on $R$
\State Move the containers based on $\pi$
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}