列/小页面中的规则算法

列/小页面中的规则算法

我正在使用 Benoit Guillon 的 Lyx 算法风格(http://bgu.perso.libertysurf.fr/) 来获得用行号标示的漂亮算法。这只是 LaTex 中算法和算法包的包装器。

我想做的是将两种算法并排放在我的单栏论文中。通常,我会像处理图形一样使用浮点数、小页面和子浮点数。但是,(尽管没有为算法定义子浮点数)包围浮点数的规则样式会在所有子浮点数/小页面中创建规则,并且规则标题区域中仅列出内部的一个算法标题。乳胶导出位于底部。紧密裁剪的剪辑显示了删除第 93-138 行后的输出:

输出缺少左算法标题,规则中没有装订线

请注意,算法标题是右侧的算法——左侧的算法标题和编号已丢失。此外,规则中没有边线。

我真正想要的只是制作单独的小页面,然后在其中设置我的算法浮点数,但我知道 Lyx 不支持这一点(根据可嵌入对象手册)。如果我尝试,我会收到乳胶错误:

Underfull \hbox (badness 10000) in paragraph at lines 122--123
[]\T1/cmr/bx/n/10 Parameters:
 []

[1

{C:/ProgramData/MiKTeX/2.9/pdftex/config/pdftex.map}]

! LaTeX Error: Float(s) lost.

(“underfull hbox”消息出现了四次——第 61、80、101、122 行。)

因此,我想我还剩下四个问题,按照答案的优先顺序排列:

  • 还有其他技巧可以隔离浮点数的范围并将两个浮点数并排放置吗?

  • 有没有一种巧妙的方法可以为文档定义子浮动布局,从而创建两个规则并为每个规则应用一个本地标题?我没有子浮动定义的经验。

  • 有没有一种巧妙的方法可以在本地布局中定义 Guillon 的“文章(算法)”类中的命令?我愿意这样做,甚至设计一个候选布局,尽管我是 Lyx 布局/样式方面的新手。

  • 如果我被迫使用 ERT,人们将如何在纯 LaTex 中设置它?

谢谢。

%% LyX 2.0.4 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{color}
\usepackage{float}
\usepackage{amsmath}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}
\providecommand{\algorithmname}{Algorithm}
\floatname{algorithm}{\protect\algorithmname}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}
\floatname{algorithm}{Algorithm}
\usepackage[noend]{algorithmic}
\newcommand{\forbody}[1]{ #1 \ENDFOR}
\newcommand{\ifbody}[1]{ #1  \ENDIF}
\newcommand{\whilebody}[1]{ #1  \ENDWHILE}
\renewcommand{\algorithmicprint}{\textbf{draw}}
 \usepackage{algolyx}

\makeatother

\usepackage{babel}
\begin{document}

\section{Intro}

blah

\begin{algorithm}
\textbf{Parameters:} $a,b$
\begin{algor}[1]
\item [{while}] $b\neq0$

\begin{algor}[1]
\item [{.}] $t\gets b$
\item [{.}] $b\gets a\;\mod t$
\item [{.}] $a\gets t$ 
\end{algor}
\item [{endwhile}]~
\item [{.}] \textbf{return} $a$
\end{algor}
\caption{\textsc{\label{alg:Gcd1}Gcd1}}
\end{algorithm}


One float, two minipages inside (Gcd2 and 3):

\begin{algorithm}
\begin{minipage}[t]{0.48\columnwidth}%
\textbf{Parameters:} $a,b$
\begin{algor}[1]
\item [{while}] $b\neq0$

\begin{algor}[1]
\item [{.}] $t\gets b$
\item [{.}] $b\gets a\;\mod t$
\item [{.}] $a\gets t$ 
\end{algor}
\item [{endwhile}]~
\item [{.}] \textbf{return} $a$
\end{algor}
\caption{\label{alg:Gcd2}\textsc{GcdLeft}}
%
\end{minipage}\hfill{}%
\begin{minipage}[t]{0.48\columnwidth}%
\textbf{Parameters:} $a,b$
\begin{algor}[1]
\item [{while}] $b\neq0$

\begin{algor}[1]
\item [{.}] $t\gets b$
\item [{.}] $b\gets a\;\mod t$
\item [{.}] $a\gets t$ 
\end{algor}
\item [{endwhile}]~
\item [{.}] \textbf{return} $a$
\end{algor}
\caption{\label{alg:Gcd3}\textsc{GcdRight}}
%
\end{minipage}
\end{algorithm}


Just in minipages on a line

\begin{center}
\begin{minipage}[t]{0.48\columnwidth}%
\textbf{}
\begin{algorithm}
\textbf{Parameters:} $a,b$
\begin{algor}[1]
\item [{while}] $b\neq0$

\begin{algor}[1]
\item [{.}] $t\gets b$
\item [{.}] $b\gets a\;\mod t$
\item [{.}] $a\gets t$ 
\end{algor}
\item [{endwhile}]~
\item [{.}] \textbf{return} $a$
\end{algor}
\textbf{\caption{\textbf{\label{alg:Gcd4}}\textsc{GcdLeftPage}}
}

\end{algorithm}
%
\end{minipage}\hfill{}%
\begin{minipage}[t]{0.48\columnwidth}%
\textbf{}
\begin{algorithm}
\textbf{Parameters:} $a,b$
\begin{algor}[1]
\item [{while}] $b\neq0$

\begin{algor}[1]
\item [{.}] $t\gets b$
\item [{.}] $b\gets a\;\mod t$
\item [{.}] $a\gets t$ 
\end{algor}
\item [{endwhile}]~
\item [{.}] \textbf{return} $a$
\end{algor}
\textbf{\caption{\textbf{\label{alg:Gcd5}}\textsc{GcdRightPage}}
}

\end{algorithm}
%
\end{minipage}
\par\end{center}

end
\end{document}

答案1

Benoit Guillon 于 2001 年为 LyX 编写了算法风格包。它algorithmic以一种有趣的形式将 LaTeX 包提供给 LyX。在编写算法时,会使用嵌套列表的潜力。(因为当时 LyX 模块不可用,所以需要使用某个文档类。但这可以修改...)

现在,如何在 LaTeX 文档中并排打印两种算法Diego 的 CS 研究博客这几乎可以完全转化为“纯”LyX。

  1. 对于每个算法浮点数执行

    • 将其“放置选项”(例如,通过右键单击)设置为“绝对在这里”以停止其浮动 -这很重要,否则会发生错误

    • 将浮动内容用小页面包围起来,小页面的宽度是列宽的一小部分(例如,列宽的 45%);

  2. 删除小页面与“插入 > 格式 > 水平空格……”“水平填充”之间的所有空白(包括新行);

  3. \begin{figure*}在第一个小页面之前和最后一个小页面之后添加 TeX 代码/ERT,\end{figure*}使算法块再次浮动。

这是 LyX 文档的图片,后面是 PDF 输出。

lyx-文档

pdf 输出

相关内容