当我使用多列时算法消失了

当我使用多列时算法消失了

这是我的代码:

\documentclass[11pt]{llncs}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{multicol}
\usepackage{fixltx2e}
\usepackage{multicol}
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
  }  
\usepackage[T1]{fontenc}
 \usepackage{comment} 
\usepackage{amsmath}                                
\setcounter{MaxMatrixCols}{20}
\usepackage[margin=1in]{geometry}
\usepackage[boxruled, linesnumbered]{algorithm2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{hyperref}
\definecolor{bl}{rgb}{0.0,0.2,0.6} 
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\usepackage{sectsty}
\hypersetup{
    colorlinks, linkcolor={dark-red},
    citecolor={dark-blue}, urlcolor={medium-blue}
}
\usepackage{graphicx}
\usepackage[compact]{titlesec} 
\begin{document}
\begin{multicols}{2}
\begin{algorithm}[!h]
\label{alg:quad}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
    do something with $S$\;
    do another thing with $A$\;
\end{algorithm}
\columnbreak
\begin{algorithm}[!h]
\label{alg:cbl}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
        do something with $S$\;
        do another thing with $A$\;
\end{algorithm}
\end{multicols}
\end{document}

该页面显示为空白。

当我删除时\begin{multicols}...\end{multicols},页面恢复正常。

我想要做的是将这两个非常短的算法并排显示出来。我该怎么做?

答案1

multicol包裹抱怨.log

multicol警告:在“multicols”环境中不允许使用浮点数和边距!

即使你认为你正在h文本中强制放置一个 ere 位置,这种情况也会发生,这似乎不应该浮动。然而,正如在如何影响 LaTeX 中图形和表格等浮动环境的位置?,放置浮点数h并不总是会产生预期的输出,也不会改变其浮动状态。

algorithm2e提供强制、非浮动H的放置,从而提供所需的输出:

在此处输入图片描述

\documentclass{article}
\usepackage{multicol}
\usepackage[margin=1in]{geometry}
\usepackage[boxruled, linesnumbered]{algorithm2e}
\begin{document}
\begin{multicols}{2}
  \begin{algorithm}[H]
    \label{alg:quad}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
    do something with $S$\;
    do another thing with $A$\;
  \end{algorithm}

  \columnbreak

  \begin{algorithm}[H]
    \label{alg:cbl}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
      do something with $S$\;
      do another thing with $A$\;
  \end{algorithm}
\end{multicols}
\end{document}

如果您只是需要并排设置两种算法,那么您可以使用单独的minipages 来设置它们:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[boxruled, linesnumbered]{algorithm2e}
\begin{document}
\noindent
\begin{minipage}{\dimexpr.5\textwidth-.5\columnsep}
  \begin{algorithm}[H]
    \label{alg:quad}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
    do something with $S$\;
    do another thing with $A$\;
  \end{algorithm}
\end{minipage}\hfill%
\begin{minipage}{\dimexpr.5\textwidth-.5\columnsep}
  \begin{algorithm}[H]
    \label{alg:cbl}
    \SetAlgoLined
    \KwData{\textsc{Something} $S$, \textsc{Another thing} $A$}
      do something with $S$\;
      do another thing with $A$\;
  \end{algorithm}%
\end{minipage}
\end{document}

上述minipages 是为了与原始柱子相适应而制作的,它们之间的间隙等于\columnsep

相关内容