Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indentation in latex algorithmic

Tags:

latex

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.

like image 1000
Anna Avatar asked Jan 07 '10 08:01

Anna


1 Answers

Try this instead:

\STATE\hspace{\algorithmicindent} do something
\STATE\hspace{\algorithmicindent} do another thing

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:

\newcommand{\INDSTATE}[1][1]{\STATE\hspace{#1\algorithmicindent}}

and then use that when you want indentation. By default, \INDSTATE indents by one level, but you can change it:

\INDSTATE do something % What you want
\INDSTATE[2] do something % Indent by twice the amount
like image 175
Alok Singhal Avatar answered Oct 14 '22 19:10

Alok Singhal