Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am working on a paper in double-column format, and I am using the algorithmic package to typeset my algorithms. One of my while loops' condition is a bit long hence doesn't fit into the column.

When I try to split the condition into several lines, it is not properly indented, as in \WHILE{this is the first line which barely fits into the column \\ this is the second line}.

I have also tried the following:

\WHILE{this is the first line which barely fits into the column \\
  \hskip\algorithmicindent this is the second line}

However, it indents the second line of the condition only as much as the body of the WHILE, it needs to be aligned with the first line of the loop condition. How can I achieve this?

MWE is as follows:

\documentclass[twocolumn]{article}

\usepackage{algorithmic}

\begin{document}

\begin{algorithmic}
  \WHILE{There is an element which satisfies \\
         \hskip\algorithmicindent properties which are long}
    \STATE{while-body}
  \ENDWHILE
\end{algorithmic}

\end{document}
share|improve this question
    
Would you be able to include a minimal working example (MWE) that illustrates your problem? This includes specifying whether you are using the algorithms bundle or algorithmicx package. –  Werner Dec 14 '11 at 16:59

1 Answer 1

up vote 2 down vote accepted

The following MWE provides \pushcode[<num>] which indents your code <num> indents (\algorithmicindent) from the left margin. The default (since <num> is optional) is 1 indent. You could also "undent" your code by specifying a negative number (be careful that this might push code into the line numbers).

enter image description here

\documentclass{article}
\usepackage{algorithmic}% http://ctan.org/pkg/algorithmic
\newcommand{\pushcode}[1][1]{\hskip\dimexpr#1\algorithmicindent\relax}
\begin{document}
\begin{algorithmic}[1]
  \WHILE{this is the first line which barely fits into the column \\
    \pushcode[2] this is the second line}
    \STATE here is some content
  \ENDWHILE
  \STATE here is some more content
\end{algorithmic}
\end{document}​
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.