Consider the following MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage[boxed, noline, linesnumbered]{algorithm2e}
\begin{document}
\begin{algorithm}[t]
\textcolor{red}{\If{test}{\KwRet $-1$\;}}
blah\;
blah\;
blah\;
\end{algorithm}
\end{document}
The output looks like this:
As you can see, not only the lines, but also the line numbers are drawn in red. I want to apply the red color only to lines.
Best Answer
You can set/change the way the numbering is formatted. And, in this case, reformat it to set it using
\color{black}
. The macro provided to set this is\SetNlSty
:The reason for the somewhat bizarre formatting choices when using
\SetNlSty
stems from its definition inalgorithm2e.sty
, together with the default of\NlSty
: