关于算法的问题

关于算法的问题

我想问一下,在双列文档中,如何让算法(如文本)从一列流到另一列?我不想像处理图形那样将其视为一个块。

有谁知道我怎样才能实现这个目标?

答案1

只要使用将其作为管理包来设置算法列表,那么它将可以跨列或跨页边界中断。如果包在框中管理算法,那么它就不会中断。

algorithmicalgorithmicx在列表中管理其算法,就像listingsalgpseudocode。下面是使用from 的示例algorithmicx

在此处输入图片描述

\documentclass[twocolumn]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[margin=1cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{algorithm,algpseudocode,caption}% http://ctan.org/pkg/{algorithms,algorithmicx,caption}
\begin{document}
\lipsum[1-5]
\captionof{algorithm}{Euclid’s algorithm}\label{euclid}
\begin{algorithmic}[1]
  \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
  \EndProcedure
\end{algorithmic}

\lipsum[6-10]
\end{document}

注意算法是不是在环境内设置algorithm,否则它将被框起来并浮动。我们通过\captionofcaption包裹

相关内容