结束后,我没有找到如何删除"=0“。我发现一些人建议删除\usepackagenoend{algpseudocode},但是在这种情况下缩进将丢失。还有别的选择吗?
\documentclass[3p,times]{article}
\usepackage{algorithm,algorithmic}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}[H]
\caption{caption}\label{algorithm_1}
\begin{algorithmic}[1]
\STATE $\mathrm{initialization}$
\FOR{steps = $1$ to $N$}
\WHILE{condition 1}
\STATE compute solution
\If{condition}
\State do 1
\Else
\If{condition 2}
\State do 2
\Else
\State do 3
\EndIf
\EndIf
\ENDWHILE
\ENDFOR ~
\end{algorithmic}
\end{algorithm}
\end{document}
我尝试使用包algorithm2e,但这并不能解决问题。对于算法的缩进,必须使用包算法伪码。
发布于 2022-11-20 19:13:01
您的文档没有编译。它会抛出错误
Command \algorithmic already defined. }
发生错误后,latex语法只检查文档的其余部分,不一定会产生合理的输出。如果您的文档中仍然有错误,那么担心一个偏离的=0
是没有意义的。相反,您应该修复包的不兼容性。
来自不同包的语法组合(\STATE
与\State
等)这样做有点困难,但以下几点似乎奏效了:
\documentclass{article}
\usepackage{float}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}[H]
\caption{caption}\label{algorithm_1}
\begin{algorithmic}[1]
\State $\mathrm{initialization}$
\For{steps = $1$ to $N$}
\While{condition 1}
\State compute solution
\If{condition}
\State do 1
\Else
\If{condition 2}
\State do 2
\Else
\State do 3
\EndIf
\EndIf
\EndWhile
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}
https://stackoverflow.com/questions/74510946
复制相似问题