帶有內嵌 if 和註解的額外行

帶有內嵌 if 和註解的額外行

我正在用 Algorithm2e 編寫一​​個演算法。

我想做一個內聯 if 並\lIf在同一行添加註釋\Comment*

\documentclass{article}

\usepackage[vlined,boxed,linesnumbered]{algorithm2e}
\DontPrintSemicolon
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{}
\SetKwComment{Comment}{}{}

\begin{document}

\begin{algorithm}[ht]
\lIf{true}{%
    foo \Comment*{bar}
}
\caption{Test}
\end{algorithm}

\end{document}

但它會產生額外的不需要的行:

如何去除它?

相關內容