latex - 如何在 Latex 中编写 do 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}
推荐阅读
- javascript - 使用 typescript 中 JSON 类型的接口创建对象
- javascript - How can you access the properties of a json?
- css - 带有可滚动主的响应式侧边栏的问题
- java - header file information necessary for .so files
- python - 解析CDATA(一更)
- java - Java map implementation that preserves insertion order AND stores keys by reference?
- java - 如何以有序的格式保存日期和时间 Firebase & Android Studio
- javascript - 在所有全局对象原型上设置方法
- android - 如何在带有数字按钮的设备上显示离子页脚?
- sql - 在具有重复数据的表中选择具有最小值的行