[Tex/LaTex] algorithm2e compact \tcc comment

algorithm2ealgorithms

Here, the \tcc{iterate over all training examples} command, produces a large gap between examples and */. Left alignment is fine. But how to reduce the gap and make it compact?

Best Answer

Use the command \SetNoFillComment locally inside an algorithm environment or use the global option nofillcomment when loading algorithm2e.

MWE (borrowed from the linked answer):

\documentclass{article}
\usepackage{xcolor}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}

\begin{document}

\begin{algorithm}[H]
\DontPrintSemicolon
\SetNoFillComment % <---------------------------
  \KwData{Training set $x$}
  $\Delta_{ji}^l := 0$ \tcp*{will be used to compute $\partial x$}
  \tcc{iterate over all training examples}
\caption{Example code}
\end{algorithm}

\end{document} 

Output:

enter image description here