Diego’s CS research blog

August 13, 2008

Side-by-Side Algorithms in LaTex

Filed under: Uncategorized — Diego @ 9:35 am

Here is the code of how to put two (or more) algorithms side by side in latex using algorithmic and algorithm packages. (The principle is the same used to put figures side-by-side).
NB: remeber to put [H] as a parameter for \begin{algorithm} (I lost a lot of time trying to understand this very simple thing)

 

\begin{figure*}[ttt!]

 \begin{minipage}[t]{3.15in}

 \begin{algorithm}[H]

\caption{Mission-side Greedy} 

\label{alg1} 

\begin{algorithmic}[1]

\STATE whatever your alg does

\FOR{each mission $M_{j}$ in sorted order} 

\STATE do something

\ENDFOR

\end{algorithmic}

\end{algorithm}

 \end{minipage}

 \hfill

 \begin{minipage}[t]{3.15in}

\begin{algorithm}[H]

\caption{Mission-side2 Greedy} 

\label{alg2} 

\begin{algorithmic}[1]

\STATE whatever your alg does

\FOR{each mission $M_{j}$ in sorted order} 

\STATE do something

\ENDFOR

\end{algorithmic}

\end{algorithm}

 \end{minipage}

 \hfill

\end{figure*}
Advertisements

3 Comments »

  1. Good stuff man, I’ve been searching for a way to wrap text around an algorithm float. When I read this post it clicked, put the algorithm environments into the minipage and use that in the wrapfigure environment.

    Comment by Ted R. — January 14, 2011 @ 9:25 am | Reply

  2. Thank you very much. I lost one day to resolve this problem. I use this solution and i don’t care why it works 🙂

    Comment by Alex — December 31, 2011 @ 2:52 pm | Reply

  3. I tried this but it doesn’t work in an IEEEtran.cls environment. Any idea why?

    Comment by Dimitris — January 14, 2013 @ 3:35 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: