2

For a good word wrap, I use this code in algorithmicx:

\parbox[t]{\dimexpr\linewidth-\algorithmicindent}{<text>\strut}

But when the code contains several nested structure leaves a block of code. How to fix it?

\documentclass{article}

\usepackage{algorithm} 
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
  \caption{Examples}\label{alg:Examples}
  \begin{algorithmic}
  \While{$Y<5$}

  \If{$quality\ge 9$}
  \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \strut}
  \EndIf

  \EndWhile
  \end{algorithmic}
\end{algorithm}

\end{document}

a busy cat http://harrix.org/2013-04-24_013858.png

0

1 Answer 1

1

Since you are inside a second block nesting level, you need two -\algorithmicindents:

\documentclass{article}
\usepackage{showframe}% just for the example 
\usepackage{algpseudocode}
\usepackage{algorithm} 

\begin{document}

\begin{algorithm}
  \caption{Examples}\label{alg:Examples}
  \begin{algorithmic}
  \While{$Y<5$}

  \If{$quality\ge 9$}
  \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent-\algorithmicindent\relax}{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \strut}
  \EndIf

  \EndWhile
  \end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

I used showframe just for visualization purposes.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .