Latex 算法中的缩进
如何在乳胶中的算法(算法)中缩进行?
我希望能够编写以下内容:
\begin{algorithm}[H]
\caption{My Awesome Program} \label{awesome-algorithm}
\begin{algorithmic}[1]
\FOR { $i=0$ to $logn$ }
\STATE Step A:
% would like the indent the next lines...
\STATE do something
\STATE do another thing
\STATE Step B
\ENDFOR
\end{algorithmic}
\end{algorithm}
如何缩进这些行? 我一直试图通过谷歌搜索找到答案,但没有成功。我希望你们能帮助我。谢谢。
我目前正在使用以下内容进行缩进:
\STATE \ \ \ \ do something
这似乎是完全错误的。但有效。
How is it possible to indent lines in an algorithm (algorithmic) in latex?
I would like to be able to write the following:
\begin{algorithm}[H]
\caption{My Awesome Program} \label{awesome-algorithm}
\begin{algorithmic}[1]
\FOR { $i=0$ to $logn$ }
\STATE Step A:
% would like the indent the next lines...
\STATE do something
\STATE do another thing
\STATE Step B
\ENDFOR
\end{algorithmic}
\end{algorithm}
How is it possible to indent those lines?
I've been trying to find the answer by googling without success. I hope you guys can help me. Thanks.
I'm currently using the following for indentation:
\STATE \ \ \ \ do something
which seems plain wrong. But works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
它应该工作得更好,因为它使用当前的缩进值来缩进。
编辑:使用 Charles 的建议,您可以定义一个新命令
\INDSTATE
:然后在需要缩进时使用它。默认情况下,
\INDSTATE
缩进一级,但您可以更改它:Try this instead:
It should work better because it uses the current indent value to indent.
Edit: Using Charles's suggestion, you could define a new command,
\INDSTATE
:and then use that when you want indentation. By default,
\INDSTATE
indents by one level, but you can change it:我无法让 Alok 工作,所以我写了这个:
然后,将“这是我的评论”放在缩进级别 3:
编辑:
我使用 algoritmicx (因此 \State 而不是 \STATE)
I couldn't get Alok's working, so I wrote this:
Then, to put "This is my comment" at indentation level 3:
Edit:
I use algoritmicx (therefore \State and not \STATE)
我建议你不要这样缩进。该包旨在以标准方式格式化伪代码,以便读者更轻松地使用。
你正试图打破这个标准。尝试重写代码以符合读者的期望会更好。
无论如何,你为什么要标记步骤 A 和 B?每个语句都应该是它自己的步骤。看来您添加了额外的结构,实际上使代码的可读性降低了。你能用评论得到同样的效果吗?将“做某事”和“做另一件事”合并成一个语句怎么样?
I would suggest you don't indent that way. The package is designed to format pseudocode in a standard way to make it easier for your readers.
You are trying to break that standard. It would be much better for to try to rewrite the code to conform to what readers expect.
Why are you labeling step A and B, anyway? Each statement is supposed to be its own step. It seems like you are adding extra structure that actually makes the code less readable. Can you get the same effect with comments? How about combining "do something" and "do another thing" into one statement?