- 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.
- Oracle Exadata性能優化
- Learning Chef
- PyTorch自動駕駛視覺感知算法實戰
- C和C++安全編碼(原書第2版)
- C語言程序設計案例式教程
- C語言程序設計
- The HTML and CSS Workshop
- 硅谷Python工程師面試指南:數據結構、算法與系統設計
- Python程序設計與算法基礎教程(第2版)(微課版)
- 深度學習原理與PyTorch實戰(第2版)
- Mockito Essentials
- Python Programming for Arduino
- Learning Unreal Engine Game Development
- Learning Image Processing with OpenCV
- AutoCAD基礎教程