Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

Controlling Line Breaks with LaTeX

23 Dec 2009

This post is but a small overview of how you can control – ward off, really – undesirable line breaks which may be either caused by spaces or hyphens.

1 Non-Breaking Spaces

The most common one is the tilde, ~, that for some reason I like calling a twiddle:

The following two~words wouldn't be taken away from each other by a line break.

I once wondered if generating a space with after a command such as \LaTeX which doesn't normally add a trailing one would be non-breaking. Well, it isn't. In this example, LATEX and Foo would be taken away from each other by a line break:

\LaTeX\ Foo

Make sure to use a twiddle in such a case, then.

2 Commands Preventing Automatic Hyphenation

A word given as argument to the \nobreak command will not be automatically hyphenated, unless it's got a hyphen or you suggested a soft hyphen where to hyphenate it if needs be. However, this command isn't used for keeping words together on a line:

The following \nobreak{two words} would be taken away from each other by a line break.

3 Commands Preventing Line Breaks

Anything given as argument to the \mbox command will be kept together on a line, regardless of their spaces or hyphens.

The following \mbox{two words} wouldn't be taken away from each other by a line break.

4 When You Overdo It

LATEX prefers allowing lines to stick out of their paragraphs when they get too long rather than letting unattractively long spaces in paragraphs. This can happen if you overdo it with keeping words together, which I did here by using \mbox{commodo id augue non}:

Overfull line caused by abusive \mbox
Overfull line caused by abusive \mbox

This line was significantly overfull but sometimes, this overfullness isn't that obvious and I quite like adding to the preamble the following code which will highlight them with a 5pt-black rule:

\overfullrule=5pt

Using the \documentclass draft option will also cause this overfull rule to be shown.

5 References