# How do I change colouring of comments using algorithmicx?

I am using the algorithm and algpseudocode packages, whilst wrapping my algorithms around algorithm and algorithmic blocks. I would like to change the colour or formatting of my comments (\Comment{...}) to make them more or less pronounced compared to standard code, as often with narrow technical documents the comment and pseudocode may come close together and the comment may perhaps overflow to the next line, slightly hampering readability.

Thanks

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Mar 30 '14 at 12:52

Just redefine the \algorithmiccomment command provided by algpseudocode. I usually use: \renewcommand{\algorithmiccomment[1]{\hfill$\triangleright$\textit{#1}}

MWE:

\documentclass{article}

\usepackage{algorithm}
\usepackage{algpseudocode}
\renewcommand{\algorithmiccomment}[1]{\hfill$\triangleright$\textit{#1}}

\begin{document}
\begin{algorithm}
\caption{An algorithm with very important comments}
\begin{algorithmic}
\If {$i\geq maxval$}
\State $i\gets 0$
\Else
\If {$i+k\leq maxval$}
\State $i\gets i+k$ \Comment{This is comment}
\EndIf
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}


Which produces:

• Please, don't use the minimal class for examples; it's not meant for this purpose. – egreg Mar 30 '14 at 14:07
• That's perfect, thanks. I managed to make my comments grey as a result. You are missing a close brace in your paragraph of text. \renewcommand{\algorithmiccomment[1]{\hfill$\triangleright$\textit{#1}} – user1585968 Mar 30 '14 at 14:13