- LaTeX Cookbook
- Stefan Kottwitz
- 991字
- 2021-07-09 21:25:03
Choosing a font for a document
The default font has the name Computer Modern and is of very good quality. It is actually a whole font family that contains bold, italic, sans-serif, typewriter, and more font versions. All the fonts are well composed to fit together.
If you would like to change the font, use a complete bundle or carefully select font families based on shape and size. That's because, besides giving a good appearance to the document overall, it is important that all font families are compliant to each other when they are used together.
In this recipe, we will take a look at some font sets and recommended combinations.
Getting ready
For the fonts you would like to use, their files should already be installed on your TeX system. If not already present, install them. Use the package manager of your LaTeX distribution, such as the MiKTeX
package manager in case of MiKTeX on Windows, or the TeX Live manager tool called tlmgr
.
In case you have TeX Live installed, it offers the possibility to install entire font collections, so you may run the tlmgr
tool at the command line:
tlmgr install collection-fontsrecommended tlmgr install collection-fontsextra
If sufficient hard disk space is available, installing all fonts or even all packages of the TeX distribution can save you from some headache later, so you would not miss any fonts.
TeX Live installs only free fonts that have no restrictions on distribution by the supplier. There's a tool called getnonfreefonts
for downloading and installing other fonts. For documentation and download, visit http://www.tug.org/fonts/getnonfreefonts/.
How to do it...
Fonts with LaTeX support often come with a package. As the author, you can load the package and that package takes care of loading and activating fonts.
So, commonly these steps would be followed in the preamble:
- Switch to the required font encoding. Most modern fonts work with T1, as explained in Chapter 2, Tuning the Text:
\usepackage[T1]{fontenc}
- Load the font package:
\usepackage{fontname}
The
fontname
parameter is the name or the short form for the name of a font that you need to know, for example, by visiting the LaTeX Font Catalogue. - If your default document font should be sans-serif, you can switch to that:
\renewcommand{\familydefault}{\sfdefault}
In the next recipe, you will see another method of choosing a font, which also works locally. Here, we continue with the document wide font choice.
There's more...
Let's take a look at some good alternative fonts. Use each code given next together with the setting \usepackage[T1]{fontenc}
.
We will take a look at a sample output so that you can compare the font selections. Note that you may see a lower quality than in a LaTeX document, as the publisher of this book accepts only images in bitmap format. This can result in a blurry or pixelated output, depending on the print or screen resolution.
You can also see the following example with the PDF output at http://latex-cookbook.net/cookbook/examples/tag/fonts/.
To demonstrate this, we will take our very first example in the first chapter, just a bit reduced. We will see how roman, sans serif, italic, and typewriter fonts harmonize.
Latin Modern is very similar to the default Computer Modern font. It is of excellent quality. This font bundle covers the usual requirements, such as having a serif, sans serif, typewriter, and symbol font. Load the fonts using the following command:
\usepackage{lmodern}
Latin Modern gives us the following appearance:

It is still similar to the one in our very first recipe.
The Kepler fonts are a complete and well-designed set of fonts in various shapes. There are upright and slanted Greek letters, bold math glyphs, old style numbers, and several weights from light to bold extended. Even slanted small caps are available. You can get the whole set using this command:
\usepackage{kpfonts}
The appearance of our sample changes to the following:

The typefaces harmonize well. They are not very heavy, for example, the typewriter code better matches the greyness of the normal text, since it doesn't look as heavy as it did in the previous sample.
Some fonts exist only as text fonts, math fonts, or in a specific shape. In such a case, it is a challenge to combine different fonts, both regarding taste and scaling. Here are some examples that work fine together:
\usepackage{libertine} \usepackage[libertine,cmintegrals,cmbraces,vvarbb]{newtxmath} \usepackage[scaled=0.95]{inconsolata}
Together they give us this appearance:

We loaded the Linux Libertine font. It is not as dense as a Times font, but denser than Computer Modern. Then, we added the newtxmath
font, but programmed it to use Libertine glyphs when appropriate other than using the Computer Modern integral and braces symbols. The last option tells newtxmath
to use another good blackboard font with \mathbb
. Try this selection and check whether you like it, omit options to compare with the default settings. For details and further features, refer to the newtx
manual via texdoc
.
Finally, we loaded the excellent monospaced font Inconsolata for typewriter font-like shape, and scaled it a bit to better match our text font.
Now, let's try another combination:
\usepackage[sc,osf]{mathpazo} \usepackage[T1,small,euler-digits]{eulervm} \usepackage[scaled=0.86]{berasans} \usepackage[scaled=0.84]{beramono}
You can see the difference, such as more upright shape for variables and integral and summation signs:

We loaded the mathpazo
package, which gives us a Palatino text font. We replaced its Palatino Italic-like math font by the Euler Virtual Math font. It's basically the Euler font with missing symbols taken from Computer Modern, which is why it is called virtual.
In addition, we loaded the Bera sans serif font and the monospaced Bera shape for the typewriter text; both are appropriately scaled.
You may have noticed the options sc
and osf
for mathpazo
, that is, for Palatino, which gives us a small caps font and uses old style figures as the default.
Now you have some good suggestions for a fine font selection. Using any of them, your document will look professionally designed and still different from a LaTeX standard document.
- 新編Visual Basic程序設計上機實驗教程
- Android Wearable Programming
- Designing Machine Learning Systems with Python
- Mastering JavaScript Object-Oriented Programming
- Python:Master the Art of Design Patterns
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(入門與提高篇)
- Windows內核編程
- 零基礎學C語言(第4版)
- Qt 4開發實踐
- Node.js 6.x Blueprints
- Game Programming using Qt 5 Beginner's Guide
- Python網絡爬蟲從入門到實踐
- JavaScript程序設計實例教程(第2版)
- Spring Microservices
- 大象:Thinking in UML(第二版)