如何减少双列文档中算法后的空间?

如何减少双列文档中算法后的空间?

我想减少文档中算法环境与其下方文本之间的空间。查看类似问题(如何删除/更改 \algorithm 环境前后的垂直间距?算法后的垂直空间) 我试过:

  • 负空间
  • 更改 textfloatsep(针对整个文档,或者在算法环境之前)
  • 更改 intextsep(似乎不太可能,因为我的算法位于页面顶部,但我还是尝试了一下)

这些都不起作用。以下是基于对第二个问题的回答得出的 MWE:

\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

答案1

您可以使用 twoculmn 模式\setlength{\dbltextfloatsep}{<length>}。它是两列浮点数和文本区域之间的间距分隔命令。

了解更多信息布局包:用户手册第 28 页。

这里有0pt \setlength{\dbltextfloatsep}{0pt}...:

在此处输入图片描述

代码:

\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}

相关内容