I am using the algorithm2e
package to write a pseudo code algorithm. I would like to add a comment with \tcp
, on the same line as an \If
statement. I managed to do so by putting the \tcp
command between parenthesis right after the \If
, but it introduces a vertical space between the If and the following line.
\usepackage[titlenumbered,ruled,noend,algo2e]{algorithm2e}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}[t]
\If(\tcp*[l]{comment}){$k = K$}{do stuff}
\If{$k \neq K$}{do other stuff}
\end{algorithm}
\end{document}
Results in:
Anyone knows how to fix that?