TransWikia.com

Prevent new page if new line is only a few words

TeX - LaTeX Asked on February 19, 2021

I have searched for a while and I am still not sure what is the correct way to handle this issue. The problem I am facing is that I have a huge block of text, which almost ends on the end of a page, but then only like a few words go on the next page, which results in a huge gap until the next chapter starts.

What can be done? I read about setting penalties, or hacking the page size. But I am unsure what is the best way (also not to damage the remainder of the document).

Here is an example what I mean:

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}

Thanks for any help.

One Answer

Before going into any details, it's worth taking a close look at a screenshot of the first page of your test document.

enter image description here

In addition to the problem of the document generating a (typographic!) widow, there are three other typographic "features" which I've highlighted in yellow in the screenshot: (a) two lines protrude noticeably into the right-hand margin; (b) two paragraphs have a final line which consists of a single word; and (c) LaTeX doesn't know that the three instances of lit. are mid-sentence abbreviations rather than sentence-ending words, leading to a distracting amount of whitespace in each case. Some persnickety readers may also want to flag the fact that (d) you're using ordinary whitespace amounts rather than thinspace between numbers and their associated units (e.g., 1 m instead of 1,m).

As it turns out, addressing some or all of these "features" can fix the typographic-widow issue as well -- at least for the test case at hand:

  • To fix feature (a), I suggest you change usepackage{babel} to usepackage[english]{babel} (of course, replace english with whatever language is appropriate for your document) and recompile. This change allows LaTeX to consider additional hyphenation points in words such as "constituting" and "underwater".

  • To fix both (b) and (c), I suggest you load the microtype package and/or issue the instruction frenchspacing in the preamble. (The two measures are not mutually exclusive, and thus can be implemented simultaneously.) Furthermore, to address point (c), consider inserting an unbreakable space (~) between lit. and its associated literal meaning.

    With either approach, the interword spacing in paragraphs 2 and 3 is tightened up just sufficiently to allow the final words of each paragraph to occur on a full line. By saving 2 whole lines, the main object of typographic concern -- the typographic widow -- is taken care of automatically.

Some additional comments:

  • Sooner or later, your habit of using ordinary whitespace between numbers and their associated units will lead to instances of them getting separated by a line break. Either insert non-breaking space (~) or make use of some of the machinery of the siunitx package, specifically, its SI macro. At first glance, it may seem more tedious to have to input SI{1}{m} rather than just 1 m. Eventually, though, you'll be glad to have imposed some additional (typographic) discipline on the input document.

  • To suppress typographic widows and orphans ("clubs" in TeX jargon) globally in TeX and LaTeX documents, you may issue the instructions

    widowpenalty10000
    orphanpenalty10000
    

    in the preamble. Warning: Immense amounts of ink have been spilled debating the question of whether or not it's a good idea to suppress all typographic widows and orphans. I don't intend to take a position in this debate; I just mean to point out that it's possible to suppress typographic widows and orphans globally.

  • Frank Mittelbach wrote an article for TUGBoat in 2018, entitled Managing forlorn paragraph lines (a.k.a. widows and orphans) in LATEX. In that piece, he discusses not only how one might identify and, if desired, suppress widow and orphan lines in a LaTeX document, but also how to identify paragraphs whose final lines consist of a single word. (Recall that your brief test document contains two such paragraphs.) He's recently created a LaTeX package called widows-and-orphans. Its intro states: "This package identifies all widows and orphans in a document to help a user to get rid of them. The act of resolving still needs to be done manually: By rewriting text, running some paragraph long or short or [by] explicitly breaking in some strategic place. It will also identify and warn about words broken across columns or pages and display formulas separated from their introductory paragraph."

  • Raphaël Pinson has created a LaTeX package called nowidow, which simplifies suppressing typographic widows and orphans on either a per-paragraph or a global basis.

  • If the typographic widows persist even after taking the measures suggested above (or if you don't want to rely on one of the packages mentioned in the preceding bullet points), you can consider adding instructions such as enlargethispage{0.5baselineskip} or enlargethispage{0.75baselineskip} just before the final paragraph on a page that precedes the typographic widow. Similarly, if you're dealing with typographic orphans, issuing instructions such as enlargethispage{-0.5baselineskip} or `enlargethispage{-1baselineskip} should get the job done.

    Use the enlargethispage approach only sparingly, though, and only towards the very end of the editing process.

  • Finally, three completely separate issues about your test document: (i) Writing 'whale', i.e, using closing quotation marks both before and after the word, is typographically unfortunate. Do use opening as well as closing quotation marks. (ii) If your document contains accented characters, it's a good idea to issue the command usepackage[T1]{fontenc} in the preamble. (iii) (An observation inspired by a comment by @egreg): Since your text uses the spelling Archaeoceti, for the sake of consistency you should also write balaena rather than balæna.

Just for fun, here's how the page looks after implementing some measures to fix features (a) thru (d) and after inserting opening quotation marks where needed. Note that the final line of the fourth paragraph is now happily located on the same page as the other material, with a whole line to spare; see the highlighted line.

enter image description here

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}

Correct answer by Mico on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP