乳胶算法中的缩进

Ann*_*nna 17 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}
Run Code Online (Sandbox Code Playgroud)

怎么可能缩进这些线?我一直试图通过谷歌搜索找到答案,但没有成功.我希望你们能帮助我.谢谢.


我目前正在使用以下内容进行缩进:

          \STATE  \ \ \ \ do something
Run Code Online (Sandbox Code Playgroud)

这似乎是完全错误的.但是有效.

Alo*_*hal 26

试试这个:

\STATE\hspace{\algorithmicindent} do something
\STATE\hspace{\algorithmicindent} do another thing
Run Code Online (Sandbox Code Playgroud)

它应该更好地工作,因为它使用当前缩进值进行缩进.

编辑:使用Charles的建议,您可以定义一个新命令,\INDSTATE:

\newcommand{\INDSTATE}[1][1]{\STATE\hspace{#1\algorithmicindent}}
Run Code Online (Sandbox Code Playgroud)

然后在需要缩进​​时使用它.默认情况下,\INDSTATE缩进一级,但您可以更改它:

\INDSTATE do something % What you want
\INDSTATE[2] do something % Indent by twice the amount
Run Code Online (Sandbox Code Playgroud)