[Tex/LaTex] How to modify line spacing in algorithm / algpseudocode

algorithmsline-spacing

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}}

Best Answer

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}

enter image description here

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