Home > Mobile >  how to remove the end for =0 in latex algorithm?
how to remove the end for =0 in latex algorithm?

Time:11-21

I didn't find how to remove the "=0" after the end for. I find some people recommended to delete \usepackage[noend]{algpseudocode}, but the indentation will be lost in this case. Is there another alternative?

\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}

I tried to use the package algorithm2e, but that does not fix the problem. the package algpseudocode is mandatory for the indentation of the algorithm

CodePudding user response:

Your document does not compile. It throws the error

Command \algorithmic already defined. }

After an error, latex only syntax checks the rest of the document, not necessarily producing sensible output. There is no point in worrying about a stray =0 if there are still errors in your document. You should instead fix the package incompatibilities.

Your combination of syntaxes from different packages (\STATE vs. \State etc.) makes this a bit difficult, but the following seems to work:

\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}

enter image description here

  • Related