I want to use \tcc
and \tcp
commands in algorithmicx
package.
Is there any way to do this?
\documentclass[12pt,a4paper]{report}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{etoolbox}
\begin{document}
\begin{figure}
\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*/} %%%I want the comment in a separate line and italic.
\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}
\caption{Euclid’s algorithm}\label{euclid}
\end{figure}
\end{document}
Best Answer
In answer to your commented request in the code, create something like
\LineComment{<comment>}
, which will set a comment right-aligned and italicized:You can format
\LineComment
the way you want. For example, usingwould wrap the line comment in
/*
...*/
:Following some guidelines in Using end-of-line delimiter in plain TeX macro, you could also use
in order to make
/
active. If used in succession//
, it captures the contents until the end-of-line character is reached, placing it in an italicized font:The above momentary redefinition of
^^M
(the end-of-line char) could be problematic, but really depends on the circumstances. Regardless, the following might be safer: