7

I'm currently typesetting some pseudocode and was up to now pretty happy with the algorithmicx package and the algpseudocode command set. However, I would now like to use the noend option to omit end lines. That works, but unfortunately introduces additional whitespace (see lines 6 and 7 in the example below). I fiddled around with negative \vspaces but could not come up with a consistent value that works in all cases.

enter image description here

\documentclass{article}
\usepackage[noend]{algpseudocode}

\begin{document}

\begin{algorithmic}[1]
  \Function{lsolve}{$L$, $b$}
    \State $x \gets b$
    \For{$j \gets 0$ to $n - 1$}
      \State $x_j \gets x_j / l_{jj}$
      \ForAll{$i > j$ where $l_{ij} \neq 0$}
        \State $x_i \gets x_i - l_{ij} x_j$
      \EndFor
    \EndFor
    \State \Return $x$
  \EndFunction
\end{algorithmic}

\end{document}

Is there any way to patch algorithmicx or do I have to finetune the pseudocode on a case by case basis?

Johannes
  • 484

1 Answers1

9

I'm not sure why the algorithmicx package does \item[]\nointerlineskip instead of doing nothing when it's processing an end instruction not to be printed.

If I patch the relevant command to do nothing, the spacing is correct, at least in this case.

\documentclass{article}
\usepackage[noend]{algpseudocode}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\ALG@doentity}{\item[]\nointerlineskip}{}{}{}
\makeatother

\begin{document}

\begin{algorithmic}[1]
  \Function{lsolve}{$L$, $b$}
    \State $x \gets b$
    \For{$j \gets 0$ to $n - 1$}
      \State $x_j \gets x_j / l_{jj}$
      \ForAll{$i > j$ where $l_{ij} \neq 0$}
        \State $x_i \gets x_i - l_{ij} x_j$
      \EndFor
    \EndFor
    \State \Return $x$
  \EndFunction
\end{algorithmic}

\end{document}

enter image description here

egreg
  • 1,121,712