Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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
share|improve this answer
    
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.