Latex 乳胶算法中的压痕

Latex 乳胶算法中的压痕,latex,Latex,如何在latex中的算法(algorithmic)中缩进行 我希望能够写出以下内容: \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... \STAT

如何在latex中的算法(algorithmic)中缩进行

我希望能够写出以下内容:

\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
这似乎完全错了。但是很有效。

试试这个:

\STATE\hspace{\algorithmicindent} do something
\STATE\hspace{\algorithmicindent} do another thing
它应该工作得更好,因为它使用当前缩进值进行缩进

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

\newcommand{\INDSTATE}[1][1]{\STATE\hspace{#1\algorithmicindent}}
然后在需要缩进时使用它。默认情况下,
\INDSTATE
缩进一级,但您可以更改它:

\INDSTATE do something % What you want
\INDSTATE[2] do something % Indent by twice the amount

我建议你不要那样缩进。该软件包旨在以标准方式格式化伪代码,以使读者更容易阅读

你在试图打破这个标准。最好是尝试重写代码以符合读者的期望


你为什么要给步骤A和步骤B贴标签?每个语句都应该是它自己的步骤。看起来您正在添加额外的结构,这实际上会降低代码的可读性。你能用评论得到同样的效果吗?把“做点什么”和“做另一件事”合并成一句话怎么样?

我无法让阿洛克工作,所以我写了以下内容:

% Put in preamable:
\usepackage{forloop}
\newcounter{ct}
\newcommand{\markdent}[1]{\forloop{ct}{0}{\value{ct} < #1}{\hspace{\algorithmicindent}}}
\newcommand{\markcomment}[1]{\Statex\markdent{#1}}
编辑:
我使用algoritmicx(因此\State和not\State)

我无法组合这些步骤。我试着用这个评论。没关系,但我想说的不太清楚。看起来Anna对这些步骤进行了分组,以便她可以在正文中讨论这些步骤。无论如何,感谢你的评论,我确实从中学到了一些东西。我猜你在写“步骤A”和“步骤B”作为元变量。。。如果你给它们命名,你可以把它们写成步骤,然后把它们的主体/实现留在后面的文本中。(如果代码允许合理的函数抽象,也可以使用函数调用。)我正要提出这个建议。。。定义INDSTATE宏似乎是值得的。问题应移至tex.stackexchange。
\markcomment{3}{"This is my comment"}