[Tex/LaTex] Reduce vertical spacing in the algorithm environment

algorithmsline-spacing

I'm using the algorithm/algorithmic packages and want to condense some of the vertical space between an algorithm's line numbers in order to save space. Ideally, I would like to remove 1 to 2mm of space between each line. Is there a way to do this with the algorithm package without editing the .sty file?

Best Answer

You can do this either by using the spacing environment from the setspace package or by using the second argument of the \fontsize command to change the value of \baselineskip; an example:

\documentclass{article}
\usepackage{algorithmic}
\usepackage{setspace}

\begin{document}

{\fontsize{10}{10}\selectfont
\begin{algorithmic}
\IF{$n$ is odd}
\RETURN \TRUE
\ELSE
\RETURN \FALSE
\ENDIF
\end{algorithmic}
}

\begin{spacing}{0.8}
\begin{algorithmic}
\IF{$n$ is odd}
\RETURN \TRUE
\ELSE
\RETURN \FALSE
\ENDIF
\end{algorithmic}
\end{spacing}

\end{document}