如果新行只有几个字,则阻止换页

如果新行只有几个字,则阻止换页

我搜索了一段时间,但仍然不确定处理这个问题的正确方法是什么。我面临的问题是,我有一大段文字,几乎在一页的末尾结束,但下一页只有几个字,这导致到下一章开始之间有很大的空白。

该怎么办?我读到过关于设置惩罚或修改页面大小的文章。但我不确定哪种方法最好(同时又不损坏文档的其余部分)。

下面是一个例子:

\documentclass[11pt]{scrreprt}
\usepackage{caption}
\usepackage{babel}
\usepackage{setspace}
\usepackage[a4paper,showframe=true]{geometry}

\begin{document}
    
    \onehalfspacing
    
    \chapter{Intro}
    
    Cetaceans (from Latin: cetus, lit. 'whale', lit. 'huge fish')[1] are aquatic mammals constituting the infraorder Cetacea. There are around 89 living species, which are divided into two parvorders. The first is the Odontoceti, the toothed whales, which consist of around 70 species, including the dolphin (which includes killer whales), porpoise, beluga whale, narwhal, sperm whale, and beaked whale. The second is the Mysticeti, the baleen (from Latin: balæna, lit. 'whale') whales, which have a filter-feeder system, and consist of fifteen species divided into three families, and include the blue whale, right whale, bowhead whale, rorqual, and gray whale.
    
    The ancient and extinct ancestors of modern whales (Archaeoceti) lived 53 to 45 million years ago. They diverged from even-toed ungulates; their closest living relatives are hippopotamuses and others such as cows and pigs. They were semiaquatic and evolved in the shallow waters that separated India from Asia. Around 30 species adapted to a fully oceanic life. Baleen whales split from toothed whales around 34 million years ago.
    
    The smallest cetacean is Maui's dolphin, at 1 m (3 ft 3 in) and 50 kg (110 lb); the largest is the blue whale,[2] at 29.9 m (98 ft) and 173 t (381,000 lb). Baleen whales have a tactile system in the short hairs (vibrissae) around their mouth; toothed whales also develop vibrissae, but lose them during fetal development or shortly after birth,[3] leaving behind electroreceptive vibrissal crypts in some species.[4] Cetaceans have well-developed senses—their eyesight and hearing are adapted for both air and water. They have a layer of fat, or blubber, under the skin to maintain body heat in cold water. Several species exhibit sexual dimorphism. Two external forelimbs are modified into flippers; two internal hindlimbs are vestigial. Cetaceans have streamlined bodies. Dolphins are able to make very tight turns at high speeds,[5] others are capable of diving to great depths. 
    
    Although cetaceans are widespread, most species prefer the colder waters of the Northern and Southern Hemispheres. They spend their lives in the water of seas and rivers; having to mate, give birth, molt or escape from predators, like killer whales, underwater. This has been enabled by unique evolutionary adaptations in their physiology and anatomy. They feed largely on fish and marine invertebrates[...]
    
    \chapter{Main}
    
\end{document}

谢谢你的帮助。

答案1

在了解任何细节之前,值得仔细查看测试文档第一页的屏幕截图。

在此处输入图片描述

除了文档生成(印刷!)孤行的问题之外,还有三个印刷“特征”,我在屏幕截图中用黄色突出显示:(a)两行明显突出到右侧边缘;(b)两个段落的最后一行由一个单词组成;(c)LaTeX 不知道三个 是lit.句中缩写而不是句末单词,导致每个情况下都有大量令人分心的空白。一些挑剔的读者可能还想标记以下事实:(d)您使用的是普通的空白量,而不是数字及其相关单位之间的细空格(例如,1 m而不是1\,m)。

事实证明,解决这些“功能”中的部分或全部也可以修复印刷寡妇问题 - 至少对于手头的测试用例而言:

  • 要修复功能 (a),我建议您更改\usepackage{babel}\usepackage[english]{babel}(当然,将其替换english为适合您的文档的任何语言)并重新编译。此更改允许 LaTeX 考虑单词“constituting”和“underwater”中的其他连字符点。

  • 为了解决 (b) 和 (c) 问题,我建议您加载软件包microtype和/或在序言中发出指令。(这两项措施并不相互排斥,因此可以同时实施。)此外,为了解决 (c) 问题,请考虑在和其相关的字面含义之间\frenchspacing插入一个不可中断的空格 ( ~) 。lit.

    无论采用哪种方法,第 2 段和第 3 段的单词间距都会收紧到刚好足以让每段的最后一个单词出现在整行上。通过节省整整 2 行,印刷关注的主要对象 —— 印刷寡妇 —— 会自动得到处理。

一些额外的评论:

  • 迟早,您习惯在数字及其相关单位之间使用普通空格,这会导致它们被换行符分隔。要么插入不间断空格 ( ~),要么利用siunitx包的一些机制,特别是它的\SI宏。乍一看,输入 似乎\SI{1}{m}比输入 更乏味1 m。但最终,您会很高兴在输入文档上施加了一些额外的(印刷)规则。

  • 抑制印刷孤行和孤儿行(TeX 术语中的“俱乐部”)全球在 TeX 和 LaTeX 文档中,你可以发出指令

    \widowpenalty10000
    \orphanpenalty10000
    

    在序言中。警告:关于是否应该禁止全部印刷孤行和印刷寡行。我无意在这场辩论中表明立场;我只是想指出,在全球范围内消除印刷孤行和印刷寡行是可能的。

  • Frank Mittelbach 为拖船2018 年,题为在 LATEX 中管理无意义的段落行(又称寡妇和孤儿行)。在那篇文章中,他不仅讨论了如何识别和(如果需要)隐藏 LaTeX 文档中的孤行和行,还讨论了如何识别最后几行由单个单词组成的段落。(回想一下,您的简短测试文档包含两个这样的段落。)他最近创建了一个名为的 LaTeX 包鳏寡孤儿。其简介中写道:“此软件包可识别文档中的所有孤行和无序行,以帮助用户摆脱它们。解决操作仍然需要手动完成:通过重写文本、使某些段落变长或变短,或在某些战略位置明确断开。它还将识别和警告跨列或跨页断开的单词,并显示与其介绍段落分开的公式。”

  • Raphaël Pinson 创建了一个名为诺寡妇,从而简化了按段落或全局抑制印刷孤行和印刷废料的操作。

  • 如果在采取上述措施后排版孤行仍然存在(或者如果您不想依赖前面提到的某个软件包),您可以考虑在排版孤行之前的页面的最后一段之前添加诸如\enlargethispage{0.5\baselineskip}或 之类的指令\enlargethispage{0.75\baselineskip}。同样,如果您要处理排版孤行,则发出诸如\enlargethispage{-0.5\baselineskip}或 `\enlargethispage{-1\baselineskip} 之类的指令应该可以完成工作。

    但是,请谨慎使用该\enlargethispage方法,并且仅在编辑过程的最后阶段使用。

  • 最后,关于您的测试文档,有三个完全不同的问题:(i)写作'whale',即在单词前后都使用右引号,在印刷上是不合适的。请使用左引号和右引号。(ii)如果您的文档包含重音字符,最好\usepackage[T1]{fontenc}在序言中发出命令。(iii)(受@egreg 的评论启发的观察):由于您的文本使用 拼写Archaeoceti,为了保持一致性,您也应该写balaena而不是balæna

只是为了好玩,以下是实施一些措施修复功能 (a) 至 (d) 并在需要的地方插入左引号后页面的样子。请注意,第四段的最后一行现在恰好与其他材料位于同一页上,还多出一整行;请参见突出显示的行。

在此处输入图片描述

\documentclass[11pt]{scrreprt}
\usepackage{caption}
\usepackage[english]{babel} % <-- 'english' option is new
\usepackage{setspace}
\usepackage[a4paper,showframe=true]{geometry}

%% new preamble commands:
\usepackage[T1]{fontenc}
\frenchspacing
\usepackage{microtype}
\usepackage[group-separator={,}]{siunitx}

\begin{document}
    
\onehalfspacing
    
\chapter{Intro}
    
Cetaceans (from Latin: cetus, lit.~`whale', lit.~`huge fish')[1] are aquatic mammals constituting the infraorder Cetacea. There are around 89 living species, which are divided into two parvorders. The first is the Odontoceti, the toothed whales, which consist of around 70 species, including the dolphin (which includes killer whales), porpoise, beluga whale, narwhal, sperm whale, and beaked whale. The second is the Mysticeti, the baleen (from Latin: balaena, lit.~`whale') whales, which have a filter-feeder system, and consist of fifteen species divided into three families, and include the blue whale, right whale, bowhead whale, rorqual, and gray whale.
    
The ancient and extinct ancestors of modern whales (Archaeoceti) lived 53 to 45 million years ago. They diverged from even-toed ungulates; their closest living relatives are hippopotamuses and others such as cows and pigs. They were semiaquatic and evolved in the shallow waters that separated India from Asia. Around 30 species adapted to a fully oceanic life. Baleen whales split from toothed whales around 34 million years ago.
    
The smallest cetacean is Maui's dolphin, at \SI{1}{m} (\SI{3}{ft} \SI{3}{in}) and \SI{50}{kg} (\SI{110}{lb}); the largest is the blue whale,[2] at \SI{29.9}{m} (\SI{98}{ft}) and \SI{173}{t} (\SI{381000}{lb}). Baleen whales have a tactile system in the short hairs (vibrissae) around their mouth; toothed whales also develop vibrissae, but lose them during fetal development or shortly after birth,[3] leaving behind electroreceptive vibrissal crypts in some species.[4] Cetaceans have well-developed senses---their eyesight and hearing are adapted for both air and water. They have a layer of fat, or blubber, under the skin to maintain body heat in cold water. Several species exhibit sexual dimorphism. Two external forelimbs are modified into flippers; two internal hindlimbs are vestigial. Cetaceans have streamlined bodies. Dolphins are able to make very tight turns at high speeds,[5] others are capable of diving to great depths. 
    
Although cetaceans are widespread, most species prefer the colder waters of the Northern and Southern Hemispheres. They spend their lives in the water of seas and rivers; having to mate, give birth, molt or escape from predators, like killer whales, underwater. This has been enabled by unique evolutionary adaptations in their physiology and anatomy. They feed largely on fish and marine invertebrates [\dots]
    
\chapter{Main}
    
\end{document}

相关内容