Improving LaTeX Margins with the microtype Package
Learn how the microtype package uses character protrusion and font expansion to smooth LaTeX’s right margin, with a concrete example and verification steps.
14 Sept 2026, 07:19 UTC

The Problem: Uneven Right Margins in LaTeX
When typesetting justified text with the default Computer Modern fonts, the right edge often shows a ragged appearance because glyphs sit exactly on the baseline and the line‑breaking algorithm cannot always achieve perfect spacing.
Thesis: Microtype’s Protrusion and Expansion Can Smooth the Edge
The microtype package adds two subtle adjustments—character protrusion and font expansion—that move glyphs slightly into the margin and vary their width, reducing the visual roughness without changing the document’s logical structure.
How to Enable Microtype
Add the package in the preamble:
\usepackage{microtype}
For pdfLaTeX this works immediately. With XeLaTeX or LuaLaTeX load fontspec first:
\usepackage{fontspec}
\usepackage{microtype}
You can fine‑tune the features with options, for example:
\usepackage[expansion=true, protrusion=true, tracking=false]{microtype}
Worked Example: Before and After
Consider a minimal document:
\documentclass{article}
\usepackage{lmodern} % optional, uses a vector version of CM
\begin{document}
\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{document}
Compile with pdflatex and observe the right margin. Then add \usepackage{microtype} to the preamble, recompile, and compare the two PDFs.
Visually, the version with microtype shows glyphs such as “f”, “j”, “r”, and commas extending a fraction of a millimeter into the margin, while repeated letters like “m” or “n” appear slightly narrower or wider in different lines. This reduces the number of hyphenations and creates a smoother optical edge.
Trade‑offs and Limitations
- Compilation time increases modestly because microtype runs extra calculations for each character.
- Some exotic fonts or custom encodings do not expose the necessary glyph metrics; in those cases protrusion may be ineffective or cause over‑protrusion.
- Document classes that already manipulate letter spacing (e.g., certain poster or beamer themes) can conflict with microtype, leading to uneven margins.
- Aggressive expansion values (> 20 %) can produce noticeable distortion; staying with the defaults or testing visually is recommended.
Practical Verification Steps
- Create two minimal files: one without microtype, one with.
- Compile both with the same engine (pdfLaTeX is safest for verification).
- Open the PDFs in a viewer that offers a measuring tool (e.g., Adobe Acrobat, Okular). Measure the distance from the left edge of the text block to the rightmost glyph on several lines; note the variance.
- Use the command line tool
pdffonts file.pdfto confirm that the same fonts are embedded in both outputs, ensuring microtype only adjusted positioning. - At high zoom (≥ 400 %), look for the slight outward strokes of characters like “f” or “j” into the margin—these are protrusion—and compare the width of repeated letters across lines to spot expansion.
Actionable Closing
If you are producing PDFs where line‑edge quality matters—such as books, reports, or academic articles—add \usepackage{microtype} to your preamble and compile with pdfLaTeX (or XeLaTeX/LuaLaTeX with fontspec). Keep the default options unless you have a specific font that requires tweaking, and verify the result with the steps above. The improvement is subtle but cumulative, giving a more professional appearance without altering the document’s logical structure.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.