The microtype package
Evens out justified text with character protrusion and font expansion; loading the package without options switches both on.
Loading the package
\usepackage{microtype}Protrusion lets hyphens, full stops and commas stick out into the margin by a fraction of their width, so the edge of the text block looks straight. Expansion makes the characters of a line up to 2% wider or narrower, so the spaces between words vary less. As a result, paragraphs need fewer hyphenations and produce fewer overfull lines.
Both features are active by default with pdfLaTeX and LuaLaTeX. No change to the text is needed.
The package also letterspaces text with \textls, which is useful for words in capitals and small capitals.
Main commands
\usepackage{microtype} | Protrusion and expansion with the default settings. |
\usepackage[expansion=false]{microtype} | Switches one feature off; the keys are protrusion, expansion and tracking. |
\microtypesetup{protrusion=false} | Changes a setting inside the document. |
\textls[100]{CAPITALS} | Letterspaces the text; the number is the extra space in thousandths of an em. |
\DisableLigatures{encoding = T1, family = tt*} | Switches ligatures off for a set of fonts, here all typewriter fonts. Preamble only. |
Complete example
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\begin{document}
\noindent\textls[100]{LETTERSPACED CAPITALS}
\begin{minipage}{6cm}
A narrow column shows the effect best. With the package, the right
margin looks straighter, the spaces between the words are more even
and fewer words have to be hyphenated at the end of a line.
\end{minipage}
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- Expansion needs vector fonts. With bitmap fonts pdfLaTeX stops with
pdfTeX error (font expansion): auto expansion is only possible with scalable fonts. Loadlmodernor another vector font. - The package reduces the warnings Overfull \hbox (263.664pt too wide) in paragraph at lines 3--6 and Underfull \hbox (badness 10000) in paragraph at lines 3--4; it does not remove all of them.