
次の 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}
2 つ (またはそれ以上) のアルゴリズムを 1 つのフローティング オブジェクトに組み合わせたいと考えています。この問題を解決する唯一の方法は、2 つのミニページを使用して、その中に新しいアルゴリズム環境を追加することです。この解決策の問題点は、アルゴリズムの上にスペースが追加されることです。これは、ドキュメントをコンパイルするとはっきりとわかります。左の列の結合されたアルゴリズムの上にはスペースがあります。右の列の単一のアルゴリズムは正しく表示されますか?
どうすれば余分なスペースを削除できますか? または、2 つのアルゴリズムを 1 つの 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
内部のインデントは 0 に設定されているため、は必要ありませんfigure
。