![算法嵌套 for 循环生成空白行](https://linux22.com/image/312257/%E7%AE%97%E6%B3%95%E5%B5%8C%E5%A5%97%20for%20%E5%BE%AA%E7%8E%AF%E7%94%9F%E6%88%90%E7%A9%BA%E7%99%BD%E8%A1%8C.png)
%!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}