在Latex中如何编写while循环?

问题描述

我已经编写了代码,但是行号不合适,代码看起来像这样:

\begin{algorithm}[H]
\caption{Algorithm}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE $Graph\ G(V,E)$

\STATE $\textbf{\textit{function}}\ $
  \Do
    \State Something
  \doWhile
\end{algorithmic}
\label{algo1}
\end{algorithm}

以上代码的输出如下:

enter image description here

如何获得正确的编号?还是在乳胶中有更简单的方法来编写do while循环?

解决方法

尝试使用algorithm2e软件包。 ;)

preview

\documentclass[a4paper,11pt]{article}
\usepackage[norelsize,linesnumbered,ruled,lined,boxed,commentsnumbered]{algorithm2e}

\begin{document}
\begin{algorithm}[H]
 \SetAlgoLined
 \LinesNumbered
 \SetKwInOut{Input}{Input}
 \Input{$Graph\ G(V,E)$}
 \SetKwProg{Function}{function}{}{end}
 \SetKwRepeat{Do}{do}{while}
 \Function{function(param: int) : int}{
     \Do{done = false}{ something }
 }
 \caption{Algorithm}
\end{algorithm}
\end{document}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...