【问题标题】:alignment for loops in Latex with algorithm2e使用 algorithm2e 对齐 Latex 中的循环
【发布时间】:2023-01-12 15:11:35
【问题描述】:

在我的 Latex 项目中编写算法时,我偶然发现了我的 for 循环中错误结束对齐的错误。我的代码:

\begin{algorithm}[H] \caption{GSDMM\;}\label{alg:GSDMM} \KwData{Documents in the input, $\vec{d}$.\;} \KwResult{Cluster labels of each document, $\vec{z}$.\;} \Begin{ initialize $m_z$, $n_z$, and $n_z^w$ as zero for each cluster $z$ \; \For{each document $d$ \in [1, D]\;} { sample a cluster for $d$: \; $z_d \leftarrow z \sim \operatorname{Multinomial}(1 / K)$ \; $m_z \leftarrow m_z+1$ and $n_z \leftarrow n_z+N_d$ \; \For{each word $w$ \in $d$\;}{ $n_z^w \leftarrow n_z^w+N_d^w$ \; } } \For{i \in [1, I]\;}{ \For{each document $d$ \in [1, D]\;}{ record the current cluster of $d$: $z = z_d$ \; $m_z \leftarrow m_z - 1$ and $n_z \leftarrow n_z - N_d$ \; \For{each word $w$ \in $d$}{ $n_z^w \leftarrow n_z^w - N_d^w$ \; } sample a cluster for $d$: \; $z_d \leftarrow z \sim p\left(z_d=z \mid \vec{z}_{\neg d}, \vec{d}\right)$ \; $m_z \leftarrow m_z+1$ and $n_z \leftarrow n_z+N_d$ \; \For{each word $w$ \in $d$\;}{ $n_z^w \leftarrow n_z^w + N_d^w$ \; } } } } \end{algorithm}

给出以下输出: output

\end{algorithm} 给出了以下错误:

errors

但我似乎找不到问题所在。 algorithm2e的包后面是\RestyleAlgo{ruled}\DontPrintSemicolon

提前致谢

【问题讨论】:

  • 您能否将您的代码作为带换行符的代码块发布?请将其扩展为minimal reproducible example,包括所有必要的包等。

标签: latex overleaf


【解决方案1】:

发现问题:它与不在数学模式中的符号元素有关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多