LaTeX and its fancy fonts
An introduction to text formatting in LaTeX.
Contents
- Attributes
- Underline
- Superscript and subscript
- Justification
- Special characters
- Breaks
- Different fonts
- Symbol fonts
- Initials
Attributes ↩
Basic font attributes in LaTeX are family, series, shape, and size. There is also encoding, but for our purposes, T1 (\usepackage[T1]{fontenc}
) will suffice.
Family
\command{text} | {\command text} | Family |
---|---|---|
\textrm |
\rmfamily |
Roman (serif) |
\textsf |
\sffamily |
Sans serif |
\texttt |
\ttfamily |
Typewriter |
Series
\command{text} | {\command text} | Series |
---|---|---|
\textmd |
\mdseries |
Medium |
\textbf |
\bfseries |
Bold |
Shape
\command{text} | {\command text} | Shape |
---|---|---|
\textit |
\itshape |
Italic |
\textsl |
\slshape |
Slanted |
\textsc |
\scshape |
Small caps |
\emph |
\em |
Emphasized |
\textulc |
\ulcshape |
Change small caps to upper/lower case |
\textup |
\upshape |
Change italic, slanted, or emphasized to upright |
\textnormal |
\normalshape |
Reset shape to normal |
Use \normalfont
command to reset it all back to default.
Size
\tiny
smallest text size\scriptsize
\footnotesize
\small
\normalsize
- default text size\large
\Large
\LARGE
\huge
\Huge
- largest text size
Keep in mind that this list of commands is not comprehensive. For more information, check out the full documentation of LaTeX font commands.1
Underline ↩
The basic way to underline the text is to use \underline
command. For more options, including various like shapes, strike-out, crossed-out, and more, check out the ulem
package.2
Superscript and subscript ↩
\textsuperscript
and \textsubscript
command will transform the text to superscript and subscript accordingly.
Verbatim ↩
To display large blocks of verbatim text, use verbatim
environment:
\begin{verbatim}
Large block of
verbatim text.
\end{verbatim}
For the short snippets, use \verb
:
\verb!verbatim text!
Starred versions (verbatim*
and \verb*
) replace spaces with "open box" character ␣
.
Justification ↩
\declaration | \begin{environment} | Justification |
---|---|---|
\justifying |
justify |
Fully justified |
\centering |
center |
Centered |
\raggedright |
flushleft |
Left-justified |
\raggedleft |
flushright |
Right-justified |
Special characters ↩
~
non-breakable space-
- (hyphen)--
– (en-dash)---
— (em-dash)`text'
‘text’ (single quotation marks)``text''
“text” (double quotation marks)<<text>>
«text» (French quotation marks),,text``
„text“ (German quotation marks)\ldots
… (ellipsis)\$
$\%
%\_
_\{
{\}
}\&
&\#
#\S
§\textbar
|\textbackslash
\
For more special characters, including accented letters, ligatures, and punctuation, see Chapter 2: "Body-text symbols" of "The Comprehensive LaTeX Symbol List".3
Breaks ↩
Line breaks
The simplest way to start a new line in LaTeX is to leave an empty line between two blocks of text. Some other useful commands are listed below:
\\
line break\\*
line break prohibiting a page break afterwards\newline
line break without starting a new paragraph
Page breaks
\newpage
starts a new page without clearing pending floats; in the multi-column environment, starts a new column\clearpage
starts a new page\cleardoublepage
starts a new right-hand (odd-numbered) page
Different fonts ↩
The LaTeX Font Catalogue4 contains the list of all free fonts available for LaTeX, including instructions on how to use them.
For example, let's say we want to change our main font to a fancier one — IM Fell English.5
\usepackage{imfellEnglish}
\usepackage[T1]{fontenc}
Usage of your own fonts is also possible through the fontspec
6 package, but requires you to use XeTeX or LuaTeX compiler.
\usepackage{fontspec}
\setmainfont{YourFontHere}
Symbol fonts ↩
If you need a rare special symbol, a glyph, or a dingbat, you most probably will find it in "The Comprehensive LATEX Symbol List".7
Another useful package in that regard, is fontawesome5
,8 that provides Font Awesome9 implementation in LaTeX.
Initials ↩
AKA drop capitals — is a letter at the beginning that is larger than the rest of the text.10 The easiest way to do this is the lettrine
11,12 package, and when combined with some fancy font from the catalogue, produces beautiful results.
example.sty
% Initials
\RequirePackage{lettrine}
\input Typocaps.fd
\newcommand*\initfamily{\usefont{U}{Typocaps}{xl}{n}}
\renewcommand{\LettrineFontHook}{\initfamily}
Basic usage of this:
lettrine[<options>]{<letter>}{<text>}
<letter>
is a drop cap, 2 lines high by default, and <text>
is the rest of the first word in small caps.
And here's how it will look in the document:
example_sub1.tex
\lettrine[lines=2]{H}{ere} is an example of a custom command
defined in \verb|example.sty| that formats a monster stat block:
There are a lot of options for this command, even to replace the initial with a custom image. Consult the package's documentation and experiment a bit.
There are more topics on text formatting and decoration, but we'll leave it for the next time.
Discuss this post on Reddit