Change the font in LaTeX (sans serif, typewriter, other typefaces)

Every LaTeX document has three font families: serif, sans serif and typewriter. \textsf{...} and \texttt{...} switch for a piece of text, \renewcommand{\familydefault}{\sfdefault} makes the whole document sans serif, and a font package replaces the typeface.

Serif, sans serif and typewriter

\textrm, \textsf and \texttt change the text in their braces. The switches \rmfamily, \sffamily and \ttfamily change all text up to the end of the group.

Serif text, \textsf{sans serif text} and \texttt{typewriter text}.

{\sffamily This sentence is sans serif up to the closing brace.}
Result
The compiled example

Open in the editor

Sans serif for the whole document

This line in the preamble makes the sans serif family the default for text, headings and captions. Formulas keep their own fonts.

This goes into the preamble.

\renewcommand{\familydefault}{\sfdefault}

Open in the editor

Another typeface with pdfLaTeX

With pdfLaTeX a typeface comes as a package. libertinus loads Libertinus Serif and Sans; newtxtext with newtxmath loads a Times-like text and math font, newpxtext a Palatino-like one, and lmodern Latin Modern, which looks like the default but scales to every size. Load fontenc with T1 as well, so accented letters are single characters of the font.

Complete document:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{libertinus}
\begin{document}
Text in Libertinus Serif and \textsf{text in Libertinus Sans}.
\end{document}
Result
The compiled example

Open in the editor

Any OpenType font with LuaLaTeX

The fontspec package loads an OpenType or TrueType font by its name, from the TeX installation or from the fonts installed on the computer. \setmainfont sets the serif family, \setsansfont the sans serif family and \setmonofont the typewriter family. The document has to be compiled with LuaLaTeX or XeLaTeX.

Complete document:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\setmonofont{Latin Modern Mono}
\begin{document}
Serif text, \textsf{sans serif text} and \texttt{typewriter text}.
\end{document}
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages