Latex 使用algorithm报错 undefined control sequence

如果是

\begin{algorithm}
\caption{The algorithm}
\label{alg:A}
\begin{algorithmic}
\STATE{vector = [0]*question\_length}
\FOR{cell in table}
\IF{contains(question,cell)}
\STATE{start\_index = get\_index(question, cell)}
\STATE{vector[start\_index:start\_index+len(cell)] = 2}
\STATE{vector[start\_index] = 1}
\STATE{vector[start\_index+len(cell)] = 3}
\STATE{break}
\ENDIF
\ENDFOR

\FOR{one in header}
\IF{contains(question,one)}
\STATE{index = get\_index(question, one)}
\STATE{vector[index] = 4}
\ENDIF
\ENDFOR

\end{algorithmic}
\end{algorithm}

则用
\usepackage{algorithm,algorithmic}

如果是

\begin{algorithm}
\caption{The algorithm}\label{alg:cap}
\begin{algorithmic}
\Require $n \gets 0$
\Ensure $y = x^n$
\State $y \gets 1$
\State $X \gets x$
\State $N \gets n$
\While{$N \neq 0$}
\If{$N$ is even}
    \State $X \gets X \times X$
    \State $N \gets \frac{N}{2}$  \Comment{This is a comment}
\ElsIf{$N$ is odd}
    \State $y \gets y \times X$
    \State $N \gets N - 1$
\EndIf
\EndWhile
\end{algorithmic}
\end{algorithm}

则用
\usepackage{algorithm,algpseudocode}

你可能感兴趣的:(LaTex,Latex)