算法嵌套 for 循环生成空白行

算法嵌套 for 循环生成空白行
%!TEX program = xelatex
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}
\begin{algorithm}[]
\caption{LDA}
\begin{algorithmic}[1]
    \FOR{$d$}
    \STATE{
      \FOR{$k\in\{1,...,K\}$} 
      \STATE{Generate$\beta_k=(\beta_{k_1},...,\beta_{k,V})^T \sim Dirichlet(\cdot\vert\eta)$} 
      \ENDFOR
    } 
    \ENDFOR
\end{algorithmic}
\end{algorithm}
\end{document}

空行

答案1

\STATE使用 时无需\FOR。后一种构造\STATE默认设置了 :

在此处输入图片描述

\documentclass{article}
\usepackage{algorithm,algorithmic,amsmath}

\begin{document}
\begin{algorithm}
  \begin{algorithmic}[1]
    \FOR{$d$}
      \FOR{$k \in \{1,\dots,K\}$}
        \STATE Generate $\beta_k = (\beta_{k_1},\dots,\beta_{k,V})^T \sim \text{Dirichlet}(\cdot\vert\eta)$
      \ENDFOR
    \ENDFOR
  \end{algorithmic}
\end{algorithm}
\end{document}

相关内容