减少算法2e中的线之间的垂直距离

减少算法2e中的线之间的垂直距离

如何在 algorithm2e 中设置行之间的默认垂直间距?特别是我正在寻找一种方法来减少这个距离。在这个问题作者询问如何增加行距。遗憾的是,该问题的答案无法适应减少行距。简单地\vspace{-.2cm}在每行后设置是不合适的。

答案1

我尝试了许多不同的设置,虽然没有明显的区别,但setstretch效果却最好。

在此处输入图片描述

\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}{
read current\;
\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}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write \textbackslash{setstretch \{0.1\} algorithms}}
\end{algorithm}

\end{document} 

相关内容