Specify Font Typeface in LaTeX

Jan. 12, 2025

(1) For a certain piece of text1

By the code \fontfamily{#1}\selectfont, where #1 is the “font code” in the following table:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
\documentclass[a4paper,landscape]{article}
\usepackage[margin=1in]{geometry}
\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}
\usepackage{lipsum}

\usepackage[T1]{fontenc}

\setlength\parindent{0pt}

\newcommand{\testfont}[1]{\fontfamily{#1}\selectfont The quick brown fox jumps over the lazy dog. 0123456789}

\begin{document}
\thispagestyle{empty}
\vspace*{\fill}
\begin{center}
	\begin{tabular}{|l|l|l|l|}
		\hline
		Font & Font package name & Font code & Example\\ \hline
		Computer Modern Roman & & cmr & \testfont{cmr}\\ \hline
		Latin Modern Roman & lmodern & lmr & \testfont{lmr}\\ \hline
		Latin Modern Dunhill & lmodern & lmdh & \testfont{lmdh}\\ \hline
		TeX Gyre Termes & tgtermes & qtm & \testfont{qtm}\\ \hline
		TeX Gyre Pagella & tgpagella & qpl & \testfont{qpl}\\ \hline
		TeX Gyre Bonum & tgbonum & qbk & \testfont{qbk}\\ \hline
		TeX Gyre Schola & tgschola & qcs & \testfont{qcs}\\ \hline
		Times & mathptmx & ptm & \testfont{ptm}\\ \hline
		Utopia / Fourier & utopia / fourier & put & \testfont{put}\\ \hline
		Palatino & palatino & ppl & \testfont{ppl}\\ \hline
		Bookman & bookman & pbk & \testfont{pbk}\\ \hline
		Charter & charter & bch & \testfont{bch}\\ \hline
		Computer Modern Sans Serif & & cmss & \testfont{cmss}\\ \hline
		Latin Modern Sans Serif & lmodern & lmss & \testfont{lmss}\\ \hline
		TeX Gyre Adventor & tgadventor & qag & \testfont{qag}\\ \hline
		TeX Gyre Heros & tgheros & qhv & \testfont{qhv}\\ \hline
		Helvetica & helvet & phv & \testfont{qhv}\\ \hline
		Computer Modern Typewriter & & cmtt & \testfont{cmtt}\\ \hline
		Latin Modern Sans Typewriter & lmodern & lmtt & \testfont{lmtt}\\ \hline
		TeX Gyre Cursor & tgcursor & qcr & \testfont{qcr}\\ \hline
		Courier & courier & pcr & \testfont{pcr}\\ \hline
	\end{tabular}
\end{center}
\vspace*{\fill}
\end{document}

image-20250112194302037

More typefaces can be found in the reference2.

(2) For the whole document1

By importing the package whose name is “font package name” mentioned in the above table, we can change the font typeface for the whole document. Take “TeX Gyre Bonum”, we have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}
\usepackage{lipsum}

\usepackage[T1]{fontenc}
\usepackage{tgbonum}

\begin{document}
    \vspace*{\fill}
    \lipsum[1-7]
    \vspace*{\fill}
\end{document}

img-1

and “Helvetica”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}
\usepackage{lipsum}

\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
    \vspace*{\fill}
    \lipsum[1-7]
    \vspace*{\fill}
\end{document}

img-1

and “Courier”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}
\usepackage{lipsum}

\usepackage[T1]{fontenc}
\usepackage{courier}
\renewcommand\familydefault{\ttdefault}

\begin{document}
    \vspace*{\fill}
    \lipsum[1-6]
    \vspace*{\fill}
\end{document}

img-1

Note that in the “Helvetica” example and “Courier” example, code \renewcommand{\familydefault}{\sfdefault}3 and \renewcommand\familydefault{\ttdefault}4 is necessary.


References