17

My question is similar to this one, I need to skip number for some lines of the algorithm. However the solution from that question does not work for me. How can I disable numbers for some lines using the algorithmic package?

This is what I have tried:

\documentclass{article}
\usepackage{algorithmic} 
\usepackage{algorithm} 

\def\NoNumber#1{{\def\alglinenumber##1{}\State #1}\addtocounter{ALG@line}{-1}}
\begin{document}

\begin{algorithmic}[1]
\STATE Compute $Pr(X_i < x)$ and $Pr(x < X_i)$ for all $i = 1, \dots, M$ and
\FOR {$i = 1, \dots, n$}
\STATE with a number
\NoNumber{ without number}
\ENDFOR
\end{algorithmic}

\end{document}
2
  • The way algorithmic numbers lines makes it very difficult to leave off a line.
    – egreg
    Apr 7 '13 at 23:28
  • @msh I added a final remark to my answer. Apr 7 '13 at 23:51
21

One option would be to use the more versatile algorithmicx package, with its algcompatible format (allowing you to use algorithmic syntax); you can use \STATEx for unnumbered lines:

\documentclass{article}
\usepackage{algcompatible}

\begin{document}

\begin{algorithmic}[1]
\IF{some condition is true}
\STATE do some processing
\ELSIF{some other condition is true}
\STATEx do some different processing
\ELSIF{some even more bizarre condition is met}
\STATEx do something else
\ELSE
\STATE do the default actions
\ENDIF
\end{algorithmic}

\end{document}

enter image description here

Of course, the use of algcompatible was suggested only if you already have your algorithms written using the algorithmic syntax and want to switch to algorithmicx without major traumatism; if you are just starting to write your algorithms, then use the algpseudocode format instead from the beginning:

\documentclass{article}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithmic}[1]
\If{some condition is true}
\State do some processing
\ElsIf{some other condition is true}
\Statex do some different processing
\ElsIf{some even more bizarre condition is met}
\Statex do something else
\Else
\State do the default actions
\EndIf
\end{algorithmic}

\end{document}
1
  • 1
    The answer below is far more simple
    – MysteryGuy
    Sep 30 '19 at 13:12
5

Add an empty line for the line break and then just write whatever you want in the next line:

\documentclass{article}
\usepackage{algorithmic} 
\usepackage{algorithm} 

\def\NoNumber#1{{\def\alglinenumber##1{}\State #1}\addtocounter{ALG@line}{-1}}
\begin{document}

\begin{algorithmic}[1]
\STATE Compute $Pr(X_i < x)$ and $Pr(x < X_i)$ for all $i = 1, \dots, M$ and
\FOR {$i = 1, \dots, n$}
\STATE with a number

without number
\ENDFOR
\end{algorithmic}

\end{document}

enter image description here

1
  • This is as simple as efficient !
    – MysteryGuy
    Sep 30 '19 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.