Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to put two figures and an algorithm side by side in a two-column document, and the figures and the algorithm should span two columns.

I have surveyed previously asked questions such as How to put algorithm and figure(s) side by side? and How to put two figures side by side in a two-column document do not answer my question.

The following is a MWE, which includes templates for figures and alorithm that I use. If you are trying to run the code, please re-name whatever eps figures you get to xx.esp and yy.eps in the same directory with the following document.

\documentclass[conference]{IEEEtran}

\usepackage[ruled]{algorithm}
\usepackage{algpseudocode}
%\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{times}
\usepackage{amssymb}
\usepackage{url}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{multirow}

\usepackage{graphicx}

\usepackage{setspace}
\usepackage{wrapfig}
\begin{document}

\title{xxx}


\maketitle


\begin{figure*}[!t]
  \centering
  \begin{minipage}[htp]{0.32\textwidth}
    \centering
    \includegraphics[width=1\textwidth]{xx.eps}
    \vspace{-0.4cm}%
    \caption{THis is figure xx}\label{fig:xx}
  \end{minipage}
  \begin{minipage}[htp]{0.32\textwidth}
    \centering
    \includegraphics[width=1\textwidth]{yy.eps}
    \vspace{-0.4cm}%
    \caption{This is figure yy.}\label{fig:yy}
  \end{minipage}
  \vspace{-0.6cm}%
\end{figure*}



\vspace{-0.2cm}%
\alglanguage{pseudocode}
\begin{algorithm}[h]
\small
\caption{\small Insert item into Hash Table (with mCBF and aCBF)}
\label{Algorithm:insert_mCBF_aCBF}
\begin{algorithmic}[1]
\Procedure{$\mathbf{InsertItem}$}{item $x$}
    \For {$i = 1 \to k$}
            \State $mCBF.C_{f_i(x)\%N}$ ++
    \EndFor
    \State $C_{min} = MAX\_VALUE$
    %\Comment{Get minimum value of $k$ counters in mCBF}
    \For {$i = 1 \to k$}
        \If {$C_{min} > mCBF.C_{f_i(x)\%N}$}
            \State $C_{min} \gets mCBF.C_{f_i(x)\%N}$
            \State $j \gets f_i(x)\%N$
            \State $m \gets i$
        \EndIf
    \EndFor
    %\State $C_{min} = min\{mCBF.C_{f_1(x)\%N},\cdot\cdot\cdot,mCBF.C_{f_k(x)\%N}\}$
    %\State $i = \textbf{SubscriptOf}(C_{min})$
    \State $B_j = B_j \cup x$
    \Comment \emph{Insert $x$ into $B_j$}
    \For {$i = 1 \to k$}
            \State $aCBF_m.C_{f_i(x)\%\textbf{LengthOf}(aCBF_m)}$ ++
    \EndFor
\EndProcedure
\Statex
\end{algorithmic}
  \vspace{-0.4cm}%
\end{algorithm}


\end{document}

I know that the asterisk (*) is meant to make the figures span two colums, but the inside minipage does not allow me to add the algorithm. Moreover, even if the minipage allows, the algorithm would be in a figure environment, which would conflict. Please help.

Edit: I upload a picture that shows what I want looks like. The two figures and the algorithm are in the same line, but span two columns.

enter image description here

share|improve this question
    
Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. –  Jubobs May 29 '13 at 5:07
    
I get a Language 'pseudocode' is not yet defined! error when I run your code. –  John Wickerson May 29 '13 at 5:19
    
@JohnWickerson Load the algpseudocode package after the other packages. Other problems with the code provided here include: no document environment, and a \LineComment command that is nowhere defined. –  Jubobs May 29 '13 at 5:22
    
@Jubobs Ah. In which case I had better wait for Bloodmoon to provide a complete document! –  John Wickerson May 29 '13 at 5:52
    
@Jubobs I am so sorry! I have updated the Minimun Working Example. I took for granted that you guys may have the packages I use. Please help! –  Bloodmoon May 29 '13 at 6:40
show 7 more comments

1 Answer

Here's one possibility:

\documentclass[conference]{IEEEtran}

\usepackage[ruled]{algorithm}
\usepackage{algpseudocode}
%\usepackage{subfigure}
\usepackage[demo]{graphicx}
\usepackage{times}
\usepackage{amssymb}
\usepackage{url}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{wrapfig}

\newcounter{tmp}

\begin{document}

\title{xxx}

\maketitle

\begin{figure*}
  \centering
  \begin{minipage}[t]{0.32\textwidth}
    \centering
    \raisebox{-\height}{\includegraphics[width=1\textwidth]{xx.eps}}
    \vspace{-0.4cm}%
    \caption{THis is figure xx}\label{fig:xx}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.32\textwidth}
    \centering
    \raisebox{-\height}{\includegraphics[width=1\textwidth]{yy.eps}}
    \vspace{-0.4cm}%
    \caption{This is figure yy.}\label{fig:yy}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.32\textwidth}
\alglanguage{pseudocode}
\renewcommand\figurename{Algorithm}
\setcounter{tmp}{\value{figure}}
\setcounter{figure}{\value{algorithm}}
\small
\caption{\small Insert item into Hash Table (with mCBF and aCBF)}
\label{Algorithm:insert_mCBF_aCBF}
\begin{algorithmic}[1]
\Procedure{$\mathbf{InsertItem}$}{item $x$}
    \For {$i = 1 \to k$}
            \State $mCBF.C_{f_i(x)\%N}$ ++
    \EndFor
    \State $C_{min} = MAX\_VALUE$
    %\Comment{Get minimum value of $k$ counters in mCBF}
    \For {$i = 1 \to k$}
        \If {$C_{min} > mCBF.C_{f_i(x)\%N}$}
            \State $C_{min} \gets mCBF.C_{f_i(x)\%N}$
            \State $j \gets f_i(x)\%N$
            \State $m \gets i$
        \EndIf
    \EndFor
    %\State $C_{min} = min\{mCBF.C_{f_1(x)\%N},\cdot\cdot\cdot,mCBF.C_{f_k(x)\%N}\}$
    %\State $i = \textbf{SubscriptOf}(C_{min})$
    \State $B_j = B_j \cup x$
    \Comment \emph{Insert $x$ into $B_j$}
    \For {$i = 1 \to k$}
            \State $aCBF_m.C_{f_i(x)\%\textbf{LengthOf}(aCBF_m)}$ ++
    \EndFor
\EndProcedure
\Statex
\end{algorithmic}
\end{minipage}
  \setcounter{figure}{\value{tmp}}
\end{figure*}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

share|improve this answer
    
I eventually get an answer! Yes, it works! But I have more than one algorithms in my document, and the caption field in this answer has changed. How can I get the same caption filed as that in the right-most of the picture in the question? –  Bloodmoon May 30 '13 at 7:56
    
@Bloodmoon please see Section B. Algorithms on page 10 of the IEEEtranHOWTO document; the use of the algorithm floating environment is not recommended when using this document class. –  Gonzalo Medina May 30 '13 at 15:36
    
I see, thank you very much! –  Bloodmoon May 30 '13 at 15:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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