Nonbreaking Spaces
By default, LaTeX will insert line breaks at any space between words. In many cases, the default produces nice results, but sometimes the breaks occur at awkward places:
4, I would walk 500
miles to make better
line breaks in my text
[23].
To force LaTeX to not break a line at a given space, replace “
” in the code with a tilde “~
”.
The result is called a nonbreaking space.
You should use nonbreaking spaces in the following cases:
Description | Example | Code |
---|---|---|
Between a number and its unit of measure | “1000 miles” | 1000~miles |
“183 billion” | 183~billion |
|
Between components of a value, such as between feet and inches | “10' 11"” | 10'~11" |
In a date, between the month and the number | “July 4” | July~4 |
Within a reference to a location in the document | “Section 4” | Section~4 |
“Fig. 1.2” | Fig.~1.2 |
|
“Theorem 3.1” | Theorem~3.1415 |
|
Before each citation | “…as was shown by Smith [12]” | ...as was shown by Smith~\cite{smith_2020} |
Before the last word of a paragraph, especially if the word is short. | “…and so we must build it.” | ...and so we must build~it. |
Before or after any number, symbol, or narrow expression that is strongly associated with the adjacent word | “width $w$” | width~$w$ |
“in $\partial S$” | in~$\partial S$ |
|
“$A$ to $B$” | $A$~to~$B$ |
Preventing Line Breaks in Equations
Using ~
to prevent line breaks only works in text.
A different approach is needed in equations.
To prevent line breaks in the middle of an equation, place curly brackets “{...}
” around the equation.
For example ${a \in A}$
will always be displayed on one line, whereas ${a^2 + b^2} = {c^2 + d^2}$
may have a line break at the equal sign but nowhere else.
Preventing Line Breaks in Titles
LaTeX’s placement of line breaks in title is often unappealing. Consider the default output of the title code, in one of my papers:
\title{ Conical Transition Graphs for Analysis of Asymptotic Stability in Hybrid Dynamical Systems }Output:
Conical Transition Graphs for
Analysis of Asymptotic Stability in Hybrid Dynamical
Systems
The placement of “Systems” alone on the third line looks unpleasant.
To force LaTeX to not orphan “Systems,” we add nonbreaking spaces between the words “Hybrid~Dynamical~Systems”.
While we’re at it, I also put ~
into “Conical~Transition~Graphs” and “Asymptotic~Stability” so that LaTeX keeps those phrases grouped together.
\title{ Conical~Transition~Graphs for Analysis of Asymptotic~Stability in Hybrid~Dynamical~Systems }Output:
Conical Transition Graphs for Analysis of
Asymptotic Stability in
Hybrid Dynamical Systems
The above result is better, because it prevents the final word from dangling alone on a line. Ultimately, though, I decided to add even more nonbreaking spaces to prevent the middle line from being narrower than the first and third, and to make the lines roughly the same length. I find the result to be a significant improvement over the default:
\title{ % Note: You need "%" after "~" if you have a line % break immediately after. Otherwise, LaTeX inserts % an extra space at the line break in the code. Conical~Transition~Graphs~for Analysis~of~% Asymptotic~Stability in~Hybrid~Dynamical~Systems }Output:
Conical Transition Graphs for
Analysis of Asymptotic Stability
in Hybrid Dynamical Systems
Adjusting LaTeX’s Automatic Line Breaking
LaTeX determines where to break lines by assigning penalties to line breaks in certain places. You can tweak these penalties to achieve fine-grained control over where automatic line breaks occur. See here for details.