I have an algorithm dealing with some very large parameter names, messing up the readability. What I've done so far is break the lines of the problematic statement (lines 4-5) manually into two separate statements. Without it the statement will go outside the page margins. The procedure signature wraps itself.
What I want to do is to indent the overflowing lines in both the procedure name and the long statement to the location of the arrows in the figure above.
How should I do this? I am open for suggestions to other packages for algorithms as well.
\documentclass[12pt,a4paper,english,twoside,titlepage]{report}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{This procedure calculates the \texttt{response} value}
\begin{algorithmic}[1]
\Procedure {CalculateResponse}{$pszMethod$, $pszDigestUri$, $pszQop$, $pszUsername$, $pszRealm$, $pszPassword$, $pszNonce$, $pszCNonce$, $pszNonceCount$}
\State $ha1 \gets DigestCalcHA1(pszUsername, pszRealm, pszPassword)$
\State $ha2 \gets DigestCalcHA2(pszMethod, pszDigestUri, pszQop)$
\State $response \gets calculateResponse(ha1, ha2,pszMethod, pszDigestUri,$
\State $pszQop,pszNonce, pszNonceCount, pszCNonce)$
\EndProcedure
\Statex
\end{algorithmic}
\end{algorithm}
\end{document}
Best Answer
One can modify the
algorithmic
enviornment so that continuation lines are indented.The change to the standard definition of the environment is that a
\parshape
command has been added to the items. The amount of indentation is controlled by a new length\continueindent
. Now you can either let latex break lines for you automatically, and so may wish to look at the question Allowing line break at ',' in inline math mode? to make this go more smoothly, or you can manually add\break
commands in the formulae. I have included an example of each in the above code.For breaks in text use
\newline
.Should you need extra indentation on a single line you can use
\break\hspace*{2em}
and\newline\hspace*{2em}
.Also consider using @JLDiaz suggestion of
\raggedright
to avoid lines being stretched too much.