将两个不同的浮动元素并排放置(独立的、浮动元素特定的标题)

将两个不同的浮动元素并排放置(独立的、浮动元素特定的标题)

我有两个浮点数,一个图形和一个算法(新的浮动环境)。我希望它们彼此相邻放置,每个都使用一半的线宽(或 48%,或任何看起来最美观的线宽)。我尝试过使用 minipage,但这(当然)不起作用,因为 minipages 不浮动。我提供了我需要彼此相邻放置的图形和算法的示例以及所需结果的图片。

\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}

这是期望的结果

期望结果

答案1

像这样

\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}

在此处输入图片描述

相关内容