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.


  • 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}}




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

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
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.