官术网_书友最值得收藏!

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:

  1. Switch to the required font encoding. Most modern fonts work with T1, as explained in Chapter 2, Tuning the Text:
    \usepackage[T1]{fontenc}
  2. 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.

  3. 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

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:

Latin Modern

It is still similar to the one in our very first recipe.

Kepler fonts

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:

Kepler fonts

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.

Font combinations

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:

Font combinations

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:

Font combinations

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.

主站蜘蛛池模板: 湖北省| 内丘县| 蒙自县| 永新县| 天镇县| 肃宁县| 肃北| 黔东| 阿坝| 陇川县| 平顶山市| 丹阳市| 吕梁市| 河南省| 和龙市| 密山市| 西昌市| 茂名市| 北票市| 渝北区| 宁都县| 泾川县| 龙南县| 夹江县| 巴林左旗| 澄城县| 仪征市| 原阳县| 台南市| 柘荣县| 乐山市| 巴塘县| 堆龙德庆县| 石棉县| 丰台区| 扶余县| 陈巴尔虎旗| 奇台县| 平陆县| 新昌县| 微山县|