【问题标题】:how to remove the end for =0 in latex algorithm?如何删除乳胶算法中 =0 的结尾?
【发布时间】:2022-11-21 03:22:35
【问题描述】:

我没有找到如何删除结束后的“=0”。 我发现有些人建议删除 \usepackage[noend]{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,但这并不能解决问题。 algpseudocode 包对于算法的缩进是强制性的

【问题讨论】:

    标签: algorithm latex


    【解决方案1】:

    您的文档无法编译。它抛出错误

    Command lgorithmic already defined. }
    

    出现错误后,仅乳胶语法会检查文档的其余部分,不一定会产生合理的输出。如果您的文档中仍然存在错误,则无需担心流浪=0。您应该改为修复包不兼容问题。

    来自不同包的语法组合(STATEState 等)使这有点困难,但以下似乎有效:

    documentclass{article}
    usepackage{float}
    usepackage{algorithm}
    usepackage{algorithmicx}
    usepackage[noend]{algpseudocode}
    
    egin{document}
    
    egin{algorithm}[H]
        caption{caption}label{algorithm_1}
        egin{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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多