[Tex/LaTex] Adjust the indentation whithin the algorithmicx-package when a line is broken

algorithmicxalgorithmsindentationline-breaking

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.

Best Answer

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.