# How to modify line spacing in algorithm / algpseudocode?

I want to increase line spacing between statements in algorithm environment. I used the setspace package as here, but it also affects the space between line breaks that is not wanted. The following is a sample code

\begin{algorithm}
\begin{algorithmic}[1]
\State lines are long so I get line breaks. I want to increase space between statements, but not between different lines of the same statement.
\State lines are long so I get line breaks. I want to increase space between statements,  but not between different lines of the same statement.
\end{algorithmic}
\end{algorithm}


In preamble I have:

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\algrenewcommand\alglinenumber[1]{{\sf\footnotesize#1}}
\usepackage{setspace}
\let\Algorithm\algorithm
\renewcommand\algorithm[1][]{\Algorithm[#1]\setstretch{1.2}}


Here's one possibility; internally, algorithmic uses a \list, so we can use the xpatch package to patch this list adding a desired value for \itemsep (in the example I used 2ex plus2pt):

\documentclass[a4paper,10pt]{report}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{xpatch}

\algrenewcommand\alglinenumber[1]{{\sffamily\footnotesize#1}}

\makeatletter
\xpatchcmd{\algorithmic}{\itemsep\z@}{\itemsep=2ex plus2pt}{}{}
\makeatother

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\State lines are long so I get line breaks. I want to increase space between statements, but not between different lines of the same statement.
\State lines are long so I get line breaks. I want to increase space between statements,  but not between different lines of the same statement.
\end{algorithmic}
\end{algorithm}

\end{document}


The patching can also be done with the help of etoolbox instead of xpatch:

\usepackage{etoolbox}

\makeatletter
\expandafter\patchcmd\csname\string\algorithmic\endcsname{\itemsep\z@}{\itemsep=2ex plus2pt}{}{}
\makeatother

• Wouldn't \xpatchcmd{\algorithmic}{\itemsep\z@}{\itemsep=2ex plus2pt }{}{} be easier? :-) – egreg Nov 29 '12 at 16:04
• @egreg hehe! Of course; I did the change. Thanks! – Gonzalo Medina Nov 29 '12 at 16:05
• Thanks. I have etoolbox but not xpatch. I will install xpatch and test. – Aydin Nov 29 '12 at 16:15
• @Aydin You can use etoolbox, but you have to say \expandafter\patchcmd\csname\string\algorithmic\endcsname instead of \xpatchcmd{\algorithmic} – egreg Nov 29 '12 at 16:22
• @egreg I've added the etoolbox option to my answer; thanks, once again :-) – Gonzalo Medina Nov 29 '12 at 16:44