- 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.
- We get a larger text size in the increasing order using
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.
- Getting Started with Citrix XenApp? 7.6
- C++ Builder 6.0下OpenGL編程技術
- Mastering Kotlin
- 實用防銹油配方與制備200例
- 假如C語言是我發明的:講給孩子聽的大師編程課
- 編譯系統透視:圖解編譯原理
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- C語言程序設計實訓教程與水平考試指導
- Python預測之美:數據分析與算法實戰(雙色)
- Using Yocto Project with BeagleBone Black
- IBM RUP參考與認證指南
- Python高性能編程(第2版)
- 軟件開發中的決策:權衡與取舍
- 菜鳥成長之路
- Python人工智能項目實戰