2

Consider the following 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}

I want to combine two (or potentially more) algorithms in one floating object. The only solution for this that I found, is to use two minipages and add a new algorithm environment within. The problem with the solution is that it adds some space above the algorithm. This is clearly visible when compiling the document. There is some space above combined algorithms in the left column. The single algorithm in the right column appears correctly?

How can I remove the additional space or is there any better solution to combine two algorithms in one float?

3

There is a \baselineskip to remove.

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

enter image description here

You don't need \noindent, because the indentation is set to zero inside figure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.