I found the `algorithmicx`

package on this page, and tried to compile this example from the pdf file.

```
\documentclass{article}
\usepackage{algorithmicx}
\begin{document}
\begin{algorithm}
\caption{Euclidâ€™s algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
```

With `pdflatex example.tex`

, I got this error.

```
! LaTeX Error: Environment algorithm undefined.
```

What's wrong with this?

## Best Answer

You need to remove

and use the following in your preamble:

The reason for this is because the

`algorithmicx`

package provides (in addition to just defining the`algorithmic`

environment through`algorithmicx.sty`

) a bundle of style files with predefined macros (like`\Procedure`

,`\Comment`

, etc), including`algpseudocode.sty`

. See the package documentation (section2.1 The packagefor more on this).One thing the

`algorithmicx`

package doesnotdefine is the floating`algorithm`

environment. That is provided by the`algorithms`

bundle. Hence the requirement to include that as well.