10

I am typesetting algorithms with the algorithm package, and I would like to add unnumbered lines in them. Is there a way to create a \State* command, the same way there is an equation* environment?

Here is an example of algorithm. I would like the \State {} line to be unnumbered, and therefore \State Step 3. to be number 3.

\documentclass{article}
\usepackage{algorithm} 
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{A title.} 
\begin{algorithmic}[1] 
\State Step 1.
\State Step 2. 
\State {}
\State Step 3.
\end{algorithmic}
\end{algorithm}

\end{document}
lockstep
  • 250,273
Drude
  • 195
  • To add input and output before MyProcedure a possibility is to add the text before \begin{algorithmic} with starred hspace \hspace*{}(see 6.3.3 Horizontal Space) and the indentation \algorithmicindent (see 4.1 Blocks and loops).

    https://tex.stackexchange.com/questions/355937/how-to-add-input-and-output-before-algorithm-procedure

    – Vinod Kumar Chauhan Oct 24 '18 at 06:52

1 Answers1

10

By virtue of the fact that you are using algpseudocode, it looks like you are actually using the algorithmicx package. From page 4 of its manual, it looks like you want the \Statex command.

If for some reason that doesn't work, a solution can be nastily hacked by forcing suppression of the line number:

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

You can then use \NoNumber like \State:

\begin{algorithm}
\caption{A title.} 
\begin{algorithmic}[1] 
\State Step 1.
\State Step 2. 
\NoNumber{This line will not have a number!}
\State Step 3.
\end{algorithmic}
\end{algorithm}
ESultanik
  • 4,410
  • This works perfectly. It seems I didn't look in the right manual... Thanks! – Drude Feb 17 '11 at 23:53
  • 1
    This solution does not work in case I want to put \NoNumber in the first line of the pseudocode, or just after \EndIf. But \Statex works perfectly. –  Feb 07 '13 at 13:43