2

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

Bloodmoon
  • 574
  • Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. – jub0bs May 29 '13 at 05:07
  • I get a Language 'pseudocode' is not yet defined! error when I run your code. – John Wickerson May 29 '13 at 05: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. – jub0bs May 29 '13 at 05:22
  • @Jubobs Ah. In which case I had better wait for Bloodmoon to provide a complete document! – John Wickerson May 29 '13 at 05: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 06:40
  • @JohnWickerson 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 06:40
  • I wonder, could you provide a picture (a rough hand-drawn one would suffice) to show what you want the result to look like? Because I'm not entirely clear on what you want. For instance, you say "two figures and an algorithm side by side" -- does that mean three things all in one row? – John Wickerson May 29 '13 at 07:16
  • @JohnWickerson Yes, the three things are all in one row. I have upload a pic. to show what I want. Thanks! – Bloodmoon May 29 '13 at 07:27
  • There's an answer here that gives some simple code for putting multiple figures side-by-side. Supposing for a moment that your algorithm were just another figure, does that work for you? And if so, then perhaps the problem has to do with the algorithm. – John Wickerson May 29 '13 at 07:34
  • @JohnWickerson that does not work for me. algorithm is not figure, I cannot put an algorithm within a '\begin{figure}...\end{figure}' environment. If this is allowed, will the caption be FIGURE or ALGORITHM? – Bloodmoon May 29 '13 at 07:45
  • @Martin Scharrer would you please help me? – Bloodmoon May 29 '13 at 14:37
  • @MartinScharrer would you please help me? – Bloodmoon May 29 '13 at 14:39

1 Answers1

1

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.

Gonzalo Medina
  • 505,128
  • 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 07: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