[Tex/LaTex] How to reduce space after an Algorithm in a two column document

algorithmsspacingtwo-column

I'd like to decrease the space between an algorithm environment and the text beneath it in my document. Looking at similar questions (How to remove/change the vertical spacing before and after an \algorithm environment? and vertical space after algorithm) I tried:

  • Negative vspace
  • Changing the textfloatsep (either for the entire document, or just before the algorithm environment)
  • Changing the intextsep (seemed unlikely, since my algorithm is at the top of a page, but I tried it anyway)

None of those worked. Here is a MWE based on an answer to the second question:

\documentclass[twocolumn]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithm*}[t]
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
  \caption{Euclid’s algorithm}\label{euclid}
\end{algorithm*}
\lipsum[10-20]
\setlength{\textfloatsep}{0pt}% Remove \textfloatsep
\begin{algorithm*}[t]
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
  \caption{Euclid’s algorithm}\label{euclid}
\end{algorithm*}
\lipsum[20-30]
\end{document}

MWE of multicolumn algorithm environments with space beneath

Best Answer

You can use for twoculmn mode \setlength{\dbltextfloatsep}{<length>}. Its the separation command for spacing between a two-column float and the text area.

For further informations The layouts package: User manual p.28.

Here with 0pt \setlength{\dbltextfloatsep}{0pt} ... :

enter image description here

Code:

\documentclass[twocolumn]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\setlength{\dbltextfloatsep}{0pt}

\begin{document}
\begin{algorithm*}[t]
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
  \caption{Euclid’s algorithm}\label{euclid}
\end{algorithm*}
\lipsum[10-20]
\begin{algorithm*}[t]
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
  \caption{Euclid’s algorithm}\label{euclid}
\end{algorithm*}
\lipsum[20-30]
\end{document}