# Colored line numbers with algorithmicx?

The fancyvrb allows me to customize line number style which I find very useful. I'm using it to give line numbers a different color and then use that same color in the text describing the code. I believe this makes it easier to locate the text describing a particular image.

Is there a way to do the same thing for pseudo code listings using algorithmicx?

-

You need to redefine what \alglinenumber does. More specifically, use something like

\algrenewcommand{\alglinenumber}[1]{\color{<color>}\footnotesize#1:}


The following example was taken from the algorithmicx documentation:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algpseudocode
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\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
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}

\bigskip

\algrenewcommand{\alglinenumber}[1]{\color{red!80!blue}\footnotesize#1:}

\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
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}

\end{algorithm}
\end{document}


Note that \alglinenumber prints the entire line number construction, including the ending :. You can modify this to suit, if you don't want the separator.

-