You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除LaTeX算法中ENDFOR后的=0?需保留缩进

解决LaTeX算法中ENDFOR后“=0”标识的问题

问题根源在于你同时加载了algorithmic和algpseudocode包,二者属于不同的算法排版体系(algorithmic是旧包,algpseudocode属于algorithmicx包),同时引入会导致命令冲突,从而出现多余的“=0”标识。以下是两种可靠的解决方法:

方案1:移除冲突包,使用标准algorithmicx命令

直接删除algorithmic包的加载语句,仅保留algorithm(用于生成浮动算法环境)和algpseudocode(提供缩进和结构化命令)。同时统一使用algpseudocode推荐的首字母大写命令(如\For、\EndFor),避免命令混淆:

\documentclass[3p,times]{article}

\usepackage{algorithm}
\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}

该方案既保留了noend选项隐藏结束块文字的功能,又能维持正常的缩进格式,彻底解决“=0”标识问题。

方案2:重定义结束命令(临时修复)

如果因特殊需求无法移除algorithmic包,可在导言区添加命令重定义,强制消除多余符号:

\renewcommand{\ENDFOR}{\algorithmicend\ \algorithmicfor}

注意:此方法属于临时补丁,未解决包冲突的本质问题,仅推荐作为无法更换包时的应急方案。

内容的提问来源于stack exchange,提问作者seif elfetni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 04:30:51