# How to add line numbers to my Algorithm in Latex

I am writing an algorithm. I am already using the following packages for algorithms:

\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{amsmath}


I am also using the \STATE tag. I tried to add the package \usepackage{algpseudocode} it started giving errors.

• Welcome to TeX.SX! Please provide a compilable document, not just fragments.
– user31729
Apr 16 '16 at 13:44
• add a compilable document ASAP. Jan 18 at 1:04

The algorithmic environment takes an optional argument. The optional argument is a number that defines the skip between line numbering. The default [0] implies no line numbering, while [1] puts a line number on every line. [2] puts a line number every second line, and so forth:

\documentclass{article}

\usepackage{algorithm,algorithmic}

\begin{document}

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

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

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

\end{document}