latex 中的格式化问题,伪代码

Formatting problem in latex , pseudo code

我正在用latex写论文报告,大部分报告已经完成,剩下的一件事就是写出所用算法的伪代码。插入的图片是我正在尝试编写的伪代码。 Main Pseudo Code example

我需要一些帮助来编写 for 循环并确定格式,这就是我所做的:

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{blindtext}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[intoc]{nomencl}
\usepackage[nottoc]{tocbibind}


\title{test}
\begin{document}

\maketitle


\begin{algorithm}
\caption{pseudo code}\label{alg:Pseudo code}
\begin{algorithmic}[1]
\State Define the maximum number of iteration.
\For {i = 1: N flies} 
\State x_i.fitness = f(x_i)   
    \EndFor  
\State x_s = argmax[f(x_i)], i \in {1,.....,N}
\State \For {i = 1:N and i \neq s}
        \State \For{d = 1:D dimensions}
        \If{U(0,1) < \triangle}
\end{algorithmic}
\end{algorithm}
\end{document}
  • \EndIf\EndFor 缺失

  • 如果你想使用下标等数学符号,\in\triangle(这不应该是 delta 吗?),你需要将它们放在数学中模式


\documentclass[12pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{blindtext}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[intoc]{nomencl}
\usepackage[nottoc]{tocbibind}


\title{test}
\begin{document}

\maketitle


\begin{algorithm}
\caption{pseudo code}\label{alg:Pseudo code}
\begin{algorithmic}[1]
\State Define the maximum number of iteration.
\For {i = 1: N flies} 
\State $x_i$.fitness = f($x_i$)   
    \EndFor{} i
\State $x_s$ = argmax[f($x_i$)], i $\in$ {1,.....,N}
\State \For {i = 1:N and i $\neq$ s}
        \State \For{d = 1:D dimensions}
        \If{U(0,1) $< \triangle$}
          Quack
        \Else
          Quack Quack
        \EndIf
        \EndFor{} d
\EndFor{} i
\end{algorithmic}
\end{algorithm}
\end{document}