如何解决在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}
以上代码的输出如下:
如何获得正确的编号?还是在乳胶中有更简单的方法来编写do while循环?
解决方法
尝试使用algorithm2e
软件包。 ;)
\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}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。