![避免在过早分页后添加空格](https://linux22.com/image/429325/%E9%81%BF%E5%85%8D%E5%9C%A8%E8%BF%87%E6%97%A9%E5%88%86%E9%A1%B5%E5%90%8E%E6%B7%BB%E5%8A%A0%E7%A9%BA%E6%A0%BC.png)
我正在使用该软件包格式化文档multicol
。由于我的某些部分经常出现短小的子节,因此我理想情况下不希望它们“分列”,这样子节标题及其所有文本总是出现在同一列中。当然,这可以通过minipage
。由于我在某些部分经常出现短小的子节,因此我理想情况下不希望它们“分列”,这样子节标题及其所有文本总是出现在同一列中。这当然可以通过如下环境牢不可破的方块。
但是,使用该环境会导致在较长部分之前出现(我们称之为过早)列中断,在前一节的所有换行符之间会添加大量空白。我希望避免这种情况,并像往常一样将前一列的内容全部堆叠在顶部。
不幸的是,使用指定的minipage
环境[t]
并没有解决我的问题,环境也没有samepage
。我在的软件包手册中也没有找到任何关于此问题的具体信息multicol
,但我认为在使用普通页面并在较长的部分之前分页而不是分栏时也应该有一个解决方案(我不确定这是否会在多列环境中工作,所以我在这个问题中添加了额外的信息)。
如果你感到困惑,这里有一个 MWE,希望可以帮你理清思绪:
\documentclass[10pt]{article}
\usepackage{multicol}
\usepackage{lipsum}
\begin{document}
\newbox\one
\newbox\two
\long\def\loremlines#1{%
\setbox\one=\vbox {%
\lipsum%
}
\setbox\two=\vsplit\one to #1\baselineskip
\unvbox\two}
\begin{multicols*}{2}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
\smallskip
\loremlines{10}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\section*{Section 3}
This is a section that starts on the left column and continues on the right. As the sections in my document are usually much smaller than this, I would not want this, and would rather have the section heading on the right column, along with all of its text.
Here is some text.
\smallskip
\loremlines{18}
On the next page I will show what I would not want to happen (using one minipage; and then on the following page one using three minipages).
\end{multicols*}
\clearpage
\begin{multicols*}{2}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 3}
This is a section that used to start on the left column and continued on the right. Now it is completely on the right (yay!) but look at the left side. What a mess! (is even worse when there are three or four really short sections on the left, and this section originally took quite a big part of the left column).
Here is some text.
\smallskip
\loremlines{18}
\end{minipage}
\end{multicols*}
\clearpage
\begin{multicols*}{2}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\end{minipage}
%the space here should go poof! else this looks fine.
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\end{minipage}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 3}
So the left side looks better than before. But still not really appealing. The space between the two sections on the left side should ideally go 'poof'.
Here is some text.
\smallskip
\loremlines{18}
\end{minipage}
\end{multicols*}
\end{document}
(定义loremlines
取自是否有与 Lipsum 相当的用于较短文本部分的程序?并且最低限度地适应)
多谢!
更新:正如 Ivan 在评论中指出的那样,我可以添加\vfill\null
手动强制空间消失。我想知道是否有可能\vfill\null
在编译后不需要手动执行任何操作(当然,在每个小页面后添加不会执行任何操作)。
答案1
使用 minipages 时需要进行的主要切换是从 转换为multicols*
。multicols
当然,将 放在\section
minipage 顶部也会丢失部分标题上方的间距,这可能不是您想要的,所以我们必须将其添加回来。
在下面的解决方案中,我定义了一个简单的环境来封装小页面和间距,并使用命令的标准间距\section
。
还要注意,lipsum 的最新版本允许您选择特定的句子进行打印,因此我利用该功能简化了您的 MWE。
\documentclass[10pt]{article}
\usepackage{multicol}
\usepackage{lipsum}
\newenvironment{myblock}{%
\vspace{3.5ex plus 1ex minus .2ex}
\begin{minipage}{0.48\textwidth}}{\end{minipage}}
\begin{document}
\begin{multicols}{2}
\begin{myblock}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
And here some more.
\lipsum[1][1-6]
\end{myblock}
\begin{myblock}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\lipsum[1][1-6]
\end{myblock}
\begin{myblock}
\section*{Section 3}
So the left side looks better than before. But still not really appealing. The space between the two sections on the left side should ideally go 'poof'.
Here is some text.
\lipsum[1][1-14]
\end{myblock}
\end{multicols}
\end{document}