- 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.
- UML和模式應用(原書第3版)
- LabVIEW程序設計基礎與應用
- 構建移動網站與APP:HTML 5移動開發入門與實戰(跨平臺移動開發叢書)
- Developing Mobile Web ArcGIS Applications
- Responsive Web Design with HTML5 and CSS3
- Kinect for Windows SDK Programming Guide
- 微信小程序項目開發實戰
- Python忍者秘籍
- Tableau 10 Bootcamp
- Getting Started with Eclipse Juno
- ASP.NET程序開發范例寶典
- C# and .NET Core Test Driven Development
- Android開發三劍客:UML、模式與測試
- Hands-On Neural Network Programming with C#
- Python+Office:輕松實現Python辦公自動化