algorithmicx \comment 命令

algorithmicx \comment 命令
\documentclass{tudelft-report}
\usepackage[utf8]{inputenc}
\usepackage{algorithm,algorithmicx,algpseudocode}
\begin{algorithm}
\caption{cICA}\label{cICA}
\begin{algorithmic}[1]
\Procedure{cICA}{}\Comment{The procedure of cICA}
\State \textbf{Initialization} $b$\Comment{Initialize the parameters}
\begin{align*}
    \mu& = 1      \quad \lambda  = 1\\
    \gamma& = 1   \quad \eta  = 1\\
    threshold& = 0.00001 \quad flag =1\\
\end{align*}
\While{$r\not=0$}\Comment{stop the loop when the changed value of weighted 
vector is larger than threshold}
\State $\mu_{t} = max\{0,\mu_{t-1}+\gamma g(w_{t-1})\}$
\State $\lambda_{t} = \lambda_{t-1}+\gamma h(w_{t-1})$
\State $\Gamma_{1} = \overline{\rho}E\{zG'_{y}(y)\} - \frac{1}{2}\mu E\{zg'_{y}(y)\}-\lambda E\{zy\}$
\State $\Gamma_{2} = \overline{\rho}E\{G"_{y^{2}}(y)\} - \frac{1}{2}\mu E\{g"_{y^{2}}(y)\}-\lambda$
\If{$norm(w_{k} - w_{k-1}) < threshold$ }
 \State flag = 0;
\Else
\State flag = 1;
\EndIf
\EndWhile\label{euclidendwhile}
\State \textbf{return} $w$\Comment{The optimal weight vector $w$}
\EndProcedure
\end{algorithmic}
\end{algorithm}

在此处输入图片描述

当我在 algorithmicx 中使用注释命令时,文本开头总是会出现一个方框。anaynoe 能帮我解决这个问题吗?

答案1

你可以重新定义方式算法\Comment作品使用

\algrenewcommand\algorithmiccomment[1]{\hfill #1}

根据这个答案,的默认行为\Comment是插入\hfill \(\triangleright\)。以上将其重新定义为不渲染符号。您也可以使用任何其他符号。

documentclass{tudeflt-report}当用另一个文档类(例如)替换时\documentclass{article},三角形被正确呈现(而不是盒子),因此这可能是所用文档类的问题。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm,algorithmicx,algpseudocode}

\algrenewcommand\algorithmiccomment[1]{\hfill #1}

\begin{document}

\begin{algorithm}
\caption{cICA}\label{cICA}
\begin{algorithmic}[1]
\Procedure{cICA}{}\Comment{The procedure of cICA}
\State \textbf{Initialization} $b$  \Comment{Initialize the parameters}
\begin{align*}
    \mu& = 1      \quad \lambda  = 1\\
    \gamma& = 1   \quad \eta  = 1\\
    threshold& = 0.00001 \quad flag =1\\
\end{align*}
\While{$r\not=0$}\Comment{stop the loop when the changed value of weighted 
vector is larger than threshold}
\State $\mu_{t} = max\{0,\mu_{t-1}+\gamma g(w_{t-1})\}$
\State $\lambda_{t} = \lambda_{t-1}+\gamma h(w_{t-1})$
\State $\Gamma_{1} = \overline{\rho}E\{zG'_{y}(y)\} - \frac{1}{2}\mu E\{zg'_{y}(y)\}-\lambda E\{zy\}$
\State $\Gamma_{2} = \overline{\rho}E\{G"_{y^{2}}(y)\} - \frac{1}{2}\mu E\{g"_{y^{2}}(y)\}-\lambda$
\If{$norm(w_{k} - w_{k-1}) < threshold$ }
 \State flag = 0;
\Else
\State flag = 1;
\EndIf
\EndWhile\label{euclidendwhile}
\State \textbf{return} $w$\Comment{The optimal weight vector $w$}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

渲染后的 LaTeX

相关内容