答案1
我认为您滥用了该工具:您不应该嵌套\WHILE
声明\STATE
。
\documentclass{article}
\usepackage{algorithmic}
\begin{document}
\begin{algorithmic} [1]
\FOR{$j \gets 0$ \TO $n - 1$}
\STATE{$t \gets A[j]$}
\STATE {$i\gets j-1$}
\WHILE{$i\geq 0$ and $A[i]>t$}
\STATE{$A[i+1]\gets A[i]$}
\STATE{$i\gets i-1$}
\ENDWHILE
\STATE{$A[i+1]\gets t$}
\ENDFOR
\end{algorithmic}
\end{document}
正如 Manuel 在评论中正确建议的那样,该noend
选项会使“End”标签消失:
\documentclass{article}
\usepackage[noend]{algorithmic}
\begin{document}
\begin{algorithmic} [1]
\FOR{$j \gets 0$ \TO $n - 1$}
\STATE{$t \gets A[j]$}
\STATE {$i\gets j-1$}
\WHILE{$i\geq 0$ and $A[i]>t$}
\STATE{$A[i+1]\gets A[i]$}
\STATE{$i\gets i-1$}
\ENDWHILE
\STATE{$A[i+1]\gets t$}
\ENDFOR
\end{algorithmic}
\end{document}