[Tex/LaTex] How to put algorithm and figure side by side in two column document

algorithmscaptionsfloatspositioning

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

Best 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.