LaTeX 多栏文档 Multiple columns

多栏文档

原  文:Multiple columns
译  者:Xovee
翻译时间:2022年2月23日

介绍

在LaTeX 中,你可以使用\twocolumn命令来轻松地创建双栏文档。如果你需要更多的文档布局,或者创建多栏文档,你可以使用multicol包。本文介绍如何使用multicol包来做到这一点:

\documentclass{article}
\usepackage{blindtext}
\usepackage{multicol}
\title{Multicols Demo}
\author{Overleaf}
\date{April 2021}

\begin{document}
\maketitle

\begin{multicols}{3}
[
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must obey.
]
\blindtext\blindtext
\end{multicols}

\end{document}

在这里插入图片描述
首先导入这个包

\usepackage{multicol}

然后我们使用multicols环境。这个环境有两个参数:

  • 列的数量。在这个例子中,我们使用了3
  • 标题文字。在方括号中输入文字的内容。这些文字将会出现在多列文本的上方。你可以使用任意 LaTeX 命令,但是不能使用浮动元素例如图片和表格。在这个例子中,我们输入了一个标题和一小段文字。

标签\begin{multicols}\end{multicols}中的文字将会以多列的格式显示。

列间隔

我们可以使用\columnsep命令来设置列之间的间隔。例如:

\documentclass{article}
\usepackage{blindtext}
\usepackage{multicol}
\setlength{\columnsep}{1cm}
\title{Second multicols Demo}
\author{Overleaf}
\date{April 2021}

\begin{document}
\maketitle

\begin{multicols}{2}
[
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must obey.
]
\blindtext\blindtext
\end{multicols}

\end{document}

在这里插入图片描述
在这里,命令\setlength{\columnsep}{1cm}把列间隔设置为一厘米。有关 LaTeX 中的长度单位可以参考这篇文章

不平衡的列

默认情况下文档中不同列中的文字数是相等的。我们可以使用multicols*改变这一点:

\documentclass{article}
\usepackage{blindtext}
\usepackage{multicol}
\setlength{\columnsep}{1cm}
\title{Second multicols Demo}
\author{Overleaf}
\date{April 2021}
\begin{document}
\maketitle
\begin{multicols*}{3}
[
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must obey.
]
\blindtext\blindtext
\end{multicols*}

\end{document}

在这里插入图片描述
我们可以看到,文字从左列到右列依次进行显示。

插入浮动元素

我们可以在多列文档中使用wrapfigwraptable来插入图片和表格。

\begin{multicols}{2}
[
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must obey.
]

Hello, here is some text without a meaning.  This text should show what 
a printed text will look like at this place.
If you read this text, you will get no information.  Really?  Is there 
no information?  Is there.

\vfill

\begin{wrapfigure}{l}{0.7\linewidth}
\includegraphics[width=\linewidth]{overleaf-logo}
\caption{This is the Overleaf logo}
\end{wrapfigure}

A blind text like this gives you information about the selected font, how 
the letters are written and an impression of the look.  This text should
contain all...

\begin{wraptable}{l}{0.7\linewidth}
\centering
\begin{tabular}{|c|c|}
\hline
Name & ISO \\
\hline
Afghanistan & AF \\
Aland Islands & AX \\
Albania    &AL  \\
Algeria   &DZ \\
American Samoa & AS \\
Andorra & AD   \\
Angola & AO \\
\hline
\end{tabular}
\caption{Table, floating element}
\label{table:ta}
\end{wraptable}

\end{multicols}

\end{document}

在这里插入图片描述
当前版本的multicol包对浮动元素的兼容性很差。如果你使用传统的figure*table*环境,它们将出现在下一页的页首或页尾,从而破坏了文档结构。上面的例子展示了一种变通的方法(并不完美,例如如果你将元素的宽度设置为\linewidth,你将会看到文字重叠)。下面简要介绍一些命令:

  • \usepackage{wrapfig}。在 preamble 中引入这个包。
  • wrapfigure环境将会插入一个被文字环绕的图片。更多信息和例子你可以参考这篇文章

插入垂直线

你可以在文档中插入垂直线来提升列之间的可读性。

\documentclass{article}
\usepackage{blindtext}
\usepackage{multicol}
\usepackage{color}
\setlength{\columnseprule}{1pt}
\def\columnseprulecolor{\color{blue}}

\begin{document}

\begin{multicols}{3}
[
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must obey.
]
Hello, here is some text without a meaning.  This text should show what 
a printed text will look like at this place.

If you read this text, you will get no information.  Really?  Is there 
no information?  Is there.

\columnbreak
\blindtext
This will be in a new column, here is some text without a meaning.  This text 
should show what a printed text will look like at this place.

If you read this text, you will get no information.  Really?  Is there 
no information?  Is there...
\end{multicols}

\blindtext

\end{document}

在这里插入图片描述
下面介绍各个命令:

  • \usepackage{color}:引入包。
  • \setlength{\columnseprule}{1pt}:这个命令设置了垂直线的宽度,它默认为 0。在上面的例子中,它的宽度为 1pt。
  • \def\columnseprulecolor{\color{blue}}:垂直线的颜色被设置为蓝色。
  • columnbreak:这个命令插入了一个列断点。在这个例子中,第二段之前会出现大片空白,以让之后的文字填充满之后的列。也就是说,断点之前的段落会均匀地填满可用的空间。
### 使用 `multicol` 实现跨列插入图片 为了实现在 Overleaf 中的排版并跨列插入图片,可以利用 `multicol` 宏包中的 `\begin{multicols}` 和 `\end{multicols}` 命令来定义区域。对于需要跨越两显示的内容,比如较大的图表或图像,则可以在这些命令之外放置相应的内容。 当涉及到具体操作时,在 LaTeX 文档中引入 `multicol` 包之后,可以通过如下方式设置: ```latex \documentclass[a4paper,10pt]{article} \usepackage{graphicx} % Required for including images \usepackage{multicol} % 设置图形宽度适应单模式下的页面布局 \newcommand{\FigWidth}{\linewidth} \begin{document} % 开始一个环境 \begin{multicols}{2} Here is some text in the first column. More text continues here... \end{multicols} % 插入一张横跨两个目宽度的大图 \begin{figure*}[t!] \centering \includegraphics[width=0.8\FigWidth]{example-image-a}% 这里替换成自己的图片路径 \caption{A wide figure spanning both columns of a two-column document layout.} \end{figure*} % 继续之前的文本流 \begin{multicols}{2} Text after the full-width image resumes as normal within this section. This paragraph will be split into multiple lines across either side depending on available space. \end{multicols} \end{document} ``` 上述代码展示了如何在 LaTeX环境中正确处理大尺寸插图的方式[^1]。通过这种方式,不仅能够保持良好的视觉效果,而且还能确保文档结构清晰有序[^2]。 值得注意的是,如果希望让浮体(浮动对象)如表格或图片严格位于指定位置而不随编译漂移,可考虑使用 `[H]` 参数作为定位符;然而这可能会破坏某些情况下自动优化后的排版质量[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值