# Reduce vertical distance between lines in algorithm2e

How do I set the default vertical spacing between lines in algorithm2e? In particular I'm looking for a way to reduce this distance. In this question the author asks how to increase the distance between lines. Unfortunately the answers to that question cannot be adapted to reduce the distance between lines. Simply setting \vspace{-.2cm}after each line is not suitable.

• No, don't use \vspace{-.2cm} after each line, use \setstretch{0.9} for example. – AboAmmar Jun 18 at 20:31
• As indicated, that does not work. typically \setstretch expects a value in the range 1..2 – Joris Kinable Jun 18 at 21:47
• Could you add an example document which shows the problem? I've tried the solution given in the linked answer and it seems to work for values below 1, too. If you decrease the spacing too much, you will hit TeX's threshold for minimum vertical space, so you may also need to adjust \lineskip. – siracusa Jun 18 at 23:43

I tried a number of different settings with no visible difference however setstretch had the greatest effect.

\documentclass{article}
\usepackage[,]{algorithm2e}

\usepackage{setspace}

\begin{document}

\begin{algorithm}[H]
\SetAlgoLined
\KwData{Default text spacing}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}

\bigskip

\begin{algorithm}
\setstretch{0.1}
\SetAlgoLined
\KwData{text spacing \textbackslash setstretch\{0.1\}}
\KwResult{how to not write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{