
Рассмотрим следующий MWE:
\documentclass[twocolumn]{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
\begin{figure}[t]
\noindent\begin{minipage}{\columnwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 1}
\end{algorithm}
\end{minipage}
\noindent\begin{minipage}{\columnwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 2}
\end{algorithm}
\end{minipage}
\end{figure}
Some text.
Then comes the next algorithm.
\pagebreak
\begin{algorithm}[t]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 3}
\end{algorithm}
And again some text.
\end{document}
Я хочу объединить два (или потенциально больше) алгоритма в один плавающий объект. Единственное решение, которое я нашел, — это использовать две мини-страницы и добавить в них новую среду алгоритма. Проблема с решением в том, что оно добавляет некоторое пространство над алгоритмом. Это хорошо видно при компиляции документа. Над объединенными алгоритмами в левом столбце есть некоторое пространство. Единственный алгоритм в правом столбце отображается правильно?
Как можно убрать лишнее пространство или есть ли лучшее решение для объединения двух алгоритмов в одном float?
решение1
Есть, что \baselineskip
удалить.
\documentclass[twocolumn]{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
\begin{figure}[tp]
\vspace*{-\baselineskip}
\begin{minipage}{\columnwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 1}
\end{algorithm}
\end{minipage}
\begin{minipage}{\columnwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 2}
\end{algorithm}
\end{minipage}
\end{figure}
Some text.
Then comes the next algorithm.
\vfill
\pagebreak
\begin{algorithm}[tp]
\begin{algorithmic}[1]
\Function{Foo}{parameters}
\State{Do something}
\State{\Return result}
\EndFunction
\end{algorithmic}
\caption{Algorithm 3}
\end{algorithm}
And again some text.
\end{document}
Вам это не нужно \noindent
, так как внутри отступ равен нулю figure
.