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

  • LaTeX Cookbook
  • Stefan Kottwitz
  • 617字
  • 2021-07-09 21:25:03

Introduction

When LaTeX was young, documents looked quite similar, since there was a precious little choice of fonts. Over time, many new fonts were invented and gained support from LaTeX.

To find the perfect fonts for your documents, visit the LaTeX font catalogue at http://www.tug.dk/FontCatalogue/.

In this chapter, we will see how to choose fonts globally and how to adjust them within the document.

Before we take off, let's take a quick look at basic LaTeX commands for switching between fonts. We keep it very short, as introductory texts usually cover it. Experienced LaTeX users may skip this section.

Basic font commands

Fonts for text have five main attributes:

  • Encoding: We covered this in the previous chapter and concluded that T1 encoding is usually a good choice for common Latin text, which can be activated by the following command:
    \usepackage[T1]{fontenc}
  • Family: This is what we we call sets of fonts of the same origin and the same type. You can switch to a font family using one of these commands:
    • \rmfamily: This is the default that switches to Roman font, which means text with serifs.
    • \sffamily: This switches to sans serif font.
    • \ttfamily: This is for typewriter font.
  • Series: This denotes how heavy a font is. Following are the commands:
    • \bfseries: This is for bold font.
    • \mdseries: This is for medium font, which is the default.
  • Shape: This attribute relates to the shape of the text; a font family can have several shapes:
    • \upshape: This switches to upright text, which is the default
    • \itshape: This switches to italics.
    • \slshape: This gives slanted text.
    • \scshape: This is for small capitals.
  • Size: The base size is specified as an option to the document class, as we did earlier. We can choose a different size:
    • We get a larger text size in the increasing order using \large, \Large, \LARGE, \huge, and \Huge.
    • We get lower text size using \small, \footnotesize, \scriptsize, and \tiny.
    • We can switch back to the normal size using \normalfont.

The effect of these commands is limited by environments. You can also limit the effect by curly braces, for example, {\bfseries ... }.

There's another more consistent syntax for modifying short pieces of text. For example. the following commands choose a font family for a piece of text:

  • \textrm{...} switches the argument to Roman text, \textsf{...} switches it to sans-serif, and \texttt{...} switches the argument to typewriter text.

Similarly, the following applies to the series and shape:

  • \textbf{...} makes the argument bold, \textmd{...} makes it medium.
  • \textit{...} applies Italics, \textsl{...} gives slanted text, \textsc{...} switches the argument to small capitals, and \textup{...} is for upright font.

That's easier to remember. There's no such command for font size. It's unusual anyway to manually change the font size within surrounding text. Just think of calculating the interline distance for the paragraph.

There's more...

Classes and packages use these font commands to define consistent styles. As the author, we state elements such as section headings, footnotes, subscripts, and emphasized snippets; while LaTeX chooses the corresponding size, shape, and series.

What if you would like to use those commands yourself? It's a very good practice to use such font commands only in the preamble, in macro definitions, not in the document's body text. For example, instead of scattering the \textbf{...} commands all over the text for bold author names, you should define an author name style using:

\newcommand{\authorname}[1]{\textbf{#1}}

This allows to implement easy and consistent changes at a single place—the preamble, for example, when you would decide to use small caps or Italics instead.

A macro for each required formatting brings logic into the text. And you can modify all occurrences at the same time by changing the macro.

主站蜘蛛池模板: 柳州市| 旬阳县| 卫辉市| 华容县| 临清市| 苏尼特右旗| 繁昌县| 精河县| 灵川县| 保德县| 弋阳县| 丰顺县| 涿州市| 平度市| 张家界市| 石家庄市| 罗源县| 灵川县| 海兴县| 柘荣县| 景德镇市| 怀化市| 兴文县| 廉江市| 宣恩县| 泾阳县| 桃园市| 贺兰县| 赣榆县| 永吉县| 阿克苏市| 中卫市| 汕头市| 宜章县| 咸丰县| 右玉县| 宝坻区| 平果县| 时尚| 建水县| 饶河县|