1

I have two floats, a figure and an algorithm (new floating environment). I want then to be placed next to each other each using half the linewidth (or 48%, or whatever looks the nicest). I have tried using minipage, but that does (of course) note work as minipages does not float. I have included an example of the figure and the algorithm I need to place next to each other and a picture of the desired result.

\documentclass[11pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}

% Tikz is used to draw the figure
\usepackage{tikz}

% Just some changes to the margins
\setlrmarginsandblock{3cm}{*}{0.875}
\setulmarginsandblock{3cm}{*}{1.2}  
\checkandfixthelayout[nearest]      

% The new floating environment
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=los,
listname=List of Algorithms,
name=Algorithm,
placement=tbp,
within=chapter,
]{algorithm}

\begin{document}
        \begin{figure}
            \centering
            \begin{tikzpicture}[scale =0.5]
            \draw [fill] (0,6) circle [radius=0.08];
            \node [left] at (0,6) {$SP_1$};    
            \draw [fill] (2,8) circle [radius=0.08];
            \node [right] at (2,8) {$DP_0$};    
            \draw [fill] (2,4) circle [radius=0.08];
            \node [left] at (2,4) {$SP_2$};    
            \draw [fill] (4,6) circle [radius=0.08];
            \node [right] at (4,6) {$DP_1$};    
            \draw [fill] (4,2) circle [radius=0.08];
            \node [left] at (4,2) {$SP_3$};    
            \draw [fill] (6,4) circle [radius=0.08];
            \node [right] at (6,4) {$DP_2$};    
            \draw [fill] (8,2) circle [radius=0.08];
            \node [right] at (8,2) {$DP_3$};    
            \draw (0,6)--(2,8);
            \draw (4,6)--(2,8);
            \draw (4,6)--(2,4);
            \draw (4,6)--(6,4);
            \draw (0,6)--(2,8);
            \draw (6,4)--(4,2);
            \draw (6,4)--(8,2);


            \node [left] at (1,7) {$\sum_{j\in\Omega_1}x_j\leq \gamma$};
            \node [right] at (3,7) {$\sum_{j\in\Omega_1}x_j\geq \gamma+1$};

            \draw[white,fill=white] (4,-2.5) circle[radius = 0.08];
            \end{tikzpicture}
            \caption{The cut--and--solve search tree.}\label{fig:CutAndSolveSearchTree}%
        \end{figure}

        \begin{algorithm}
        \fbox{
            \parbox{0.94\linewidth}{

                \textbf{Input:} A mixed inter programming problem.\\
                \textbf{Output:} An optimal solution $x^*$ to a problem.
                \begin{description}
                    \item[Step 1] (Initialization) Set $L=-\infty$, $UB=\infty$, and set the set of piecing cuts $H = \emptyset$. 
                    \item[Step 2] (Dense problem) Solve a relaxation of the problem with all piercing cuts in $H$ added. Let the solution value be $L$.
                    \item[Step 3] (Termination check) If $L\geq UB$, return the incumbent.
                    \item[Step 4] (Piercing cut selection) Select an index set variables $\Omega$ for the piercing cut.
                    \item[Step 5] (Sparse problem) Solve the problem with $x_j=0$ for all $j\in\Omega$.
                    \item[Step 6] (Incumbent update) If the solution found in Step 4 improves the incumbent, then update $UB$. If $L\geq UB$, return the incumbent.
                    \item[Step 7] (Adding piercing cut) Add piercing cut $\sum_{j\in\Omega}x_j\geq 1$ to $H$ and go to Step 1.
                \end{description}
            }
        }
        \caption{Algorithm}{A description of a generic cut--and--solve algorithm.}\label{alg:CutAndSolveGeneric}
        \end{algorithm} 
\end{document}

And this is the desired result

Desired result

  • 1
    You'll have to place them into the same float construction (either figure or algorithm and then use the caption package and its \captionof feature to change the type of the other float. – daleif Apr 11 '16 at 7:35
  • I imagine that when you say "place them into the same float construction" you mean something like using subfloat inside a e.g. figure environment in order for the alg and the fig to place next to each other? However, when I place both the figure and th algorithm in a fig-env, each in separate subfloats, and use the \captionof I get the quite funky message You can't use \hrule here except with leaders. But I don't use any \hrule's (intentionally). – Sune Apr 11 '16 at 13:06
  • no need for subfloat, these are not two subinstances of, say, figure, just wrap them in a minipage each, and include the caption in each minipage – daleif Apr 11 '16 at 13:22
1

Something like this

\documentclass[11pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}

% Tikz is used to draw the figure
\usepackage{tikz}

% Just some changes to the margins
\setlrmarginsandblock{3cm}{*}{0.875}
\setulmarginsandblock{3cm}{*}{1.2}  
\checkandfixthelayout[nearest]      

\usepackage{caption}


% The new floating environment
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=los,
listname=List of Algorithms,
name=Algorithm,
placement=tbp,
within=chapter,
]{algorithm}

\begin{document}
        \begin{figure}
            \centering
            \begin{minipage}{0.48\linewidth}
              \centering
              some image
            \end{minipage}
            \hfill
            \begin{minipage}{0.48\linewidth}
              \begin{framed}
                some algorithm
              \end{framed}
           \end{minipage}

           \begin{minipage}[t]{0.48\linewidth}
                           \caption{The cut--and--solve search
                tree.}\label{fig:CutAndSolveSearchTree}%
           \end{minipage}
           \begin{minipage}[t]{0.48\linewidth}
             \captionof{algorithm}{A description of a generic
               cut--and--solve
               algorithm.}\label{alg:CutAndSolveGeneric}
           \end{minipage}
        \end{figure}
\end{document}

enter image description here

  • Ahh. Would definitely not have thought of that. Works like a charm, though! – Sune Apr 12 '16 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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