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 have this code

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
   \caption{Minimal Working Example for my Problem}
\begin{algorithmic}[1]
   \While{Indentation is a mess}
      \State Examine a very long line that looks horrible because the indentation is all messed up.
   \EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}​

I would want the broken text to be indented to the same column, where the statement began.

share|improve this question

1 Answer 1

Wrap your long line in a top-aligned \parbox:

enter image description here

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithm}
  \caption{Minimal Working Example for my Problem}
  \begin{algorithmic}[1]
    \While{Indentation is a mess}
      \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{Examine a very long line that looks horrible 
        because the indentation is all messed up.\strut}
    \EndWhile
  \end{algorithmic}
\end{algorithm}
\end{document}​

The current indentation (\algorithmicindent) is removed from \linewidth to fit exactly within the horizontal line width. Adding a \strut at the end allows for proper vertical alignment between lines (or \States) in lines that have no descenders.

share|improve this answer
1  
Thanks. Works well. Is there a way to make this the default behaviour? –  Tom Aug 24 '12 at 5:50
    
@Tom: I'll have to look at the source code and see. I'll get back to you if I find anything. –  Werner Aug 24 '12 at 14:27
    
@Tom: I'm sure this is possible, but it would be difficult. One would have to capture the content - not easily done - and pass it to \parbox. –  Werner Oct 7 '12 at 6:12

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.