[Tex/LaTex] Formatting algorithms to gain place in the document

algorithmspositioning

I have two algorithms in a latex document using a class document of one column. The first algorithm take almost one page, and the second one is on the next page. Is there ant way to format this to gain some place in the document. Maybe putting the two algorithms on the same pages (I don't know if it is possible).

I use \usepackage{algorithm} and \usepackage{algpseudocode}. This is an example of the two algorithms (actually they are longer than this, this is just an example).

\begin{algorithm}
\caption{My First Algorithm (param)}
\label{algo1}
\begin{algorithmic}[1]
\State $A = A + param$
\State $\alpha = 34$
\State etc ...
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{My Second Algorithm (A)}
\label{algo1}
\begin{algorithmic}[1]
\State $C = C + A$
\State $\alpha = \beta$
\State etc ...
\end{algorithmic}
\end{algorithm}

Best Answer

This a a slight modification of How to put algorithm and figure(s) side by side?

Here is a minimal example showing how to pair algorithms side-by-side:

enter image description here

\documentclass{llncs}% http://www.springer.com/computer/lncs/lncs+authors?SGWID=0-40209-0-0-0
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage[compatibility=false]{caption}% http://ctan.org/pkg/caption
\begin{document}
\lipsum[1]

\medskip

\noindent\begin{minipage}{.5\textwidth}
\captionof{algorithm}{Euclid’s algorithm}\label{algo1}
\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
    \State \textbf{return} $b$\Comment{The gcd is b}
  \EndProcedure
\end{algorithmic}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\captionof{algorithm}{Euclid’s algorithm}\label{algo2}
\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
    \State \textbf{return} $b$\Comment{The gcd is b}
  \EndProcedure
\end{algorithmic}
\end{minipage}

\medskip

On the left is Algorithm~\ref{algo1}. On the right is Algorithm~\ref{algo2}.

\lipsum[2]

\end{document}

The idea behind this approach is to have two minipages spanning the entire \linewidth. These minipages then house the non-floating algorithmic environments, as well as the non-floating \captionof caption. If need be, you can wrap the entire double minipage inside a floating algorithm environment.

The use of geometry was just to gain some stock real estate (may not be required in your instance), while lipsum provided some dummy text, Lorem ipsum style.

caption provides the means to have a caption outside of a float via \captionof. However, it requires the compatibility=false option to work, since llncs already redefines \caption - detected by caption. algorithm is still required, since it provides the algorithm counter and "List of Algorithms" capability.