LaTeX’s default font is Computer Modern. Which way you change it depends on your compiler: font packages for pdfLaTeX, or any installed font through fontspec with XeLaTeX or LuaLaTeX.
What you’ll learn
- Change the font size
- Switch the whole document to sans-serif or monospace
- Pick a font package for pdfLaTeX
- Use any installed font with fontspec
- Style headings and individual words
Change the font size
Use this when you want bigger or smaller text for the whole document or one passage.
Set the base size with a class option. The standard classes (article, report, book) accept 10pt (default), 11pt and 12pt:
\documentclass[12pt]{article}Change the size locally with a size command inside braces:
\documentclass[12pt]{article}\begin{document}This is the default text size.
{\large This is large text.}
{\small This is small text.}
{\footnotesize This is footnote-sized text.}\end{document}
Size commands are declarations: they affect everything after them until the closing brace. Their actual size depends on the base size:
| Command | Size with 10pt base | Command | Size with 10pt base |
|---|---|---|---|
\tiny | 5pt | \large | 12pt |
\scriptsize | 7pt | \Large | 14.4pt |
\footnotesize | 8pt | \LARGE | 17.28pt |
\small | 9pt | \huge | 20.74pt |
\normalsize | 10pt | \Huge | 24.88pt |
For an exact size, use \fontsize{size}{baselineskip}\selectfont, for example {\fontsize{14}{17}\selectfont Text}. For a 14pt body, use \documentclass[14pt]{extarticle} from the extsizes package.
Change the font family
Use this when the whole document, or a passage, should be serif, sans-serif or monospace.
LaTeX has three families: roman (serif, the default), sans-serif and typewriter (monospace). To change the default family for the whole document, redefine \familydefault in the preamble:
% Whole document in sans-serif\renewcommand{\familydefault}{\sfdefault}
% Whole document in monospace\renewcommand{\familydefault}{\ttdefault}Warning:
\documentclass[sans]{article}is not a valid option. LaTeX ignores it and logsUnused global option(s): [sans], so the document stays serif.
For a few words, use the text commands:
- Serif:
\textrm{...} - Sans-serif:
\textsf{...} - Monospace:
\texttt{...}
\documentclass{article}\usepackage{courier} % changes only the monospace (\texttt) font\begin{document}This is the default serif text.
\textsf{This is sans-serif text.}
\texttt{This is monospace text.}
This is regular text, but here is some code: \texttt{int x = 0;}\end{document}
Result: body text stays serif, \textsf gives sans-serif, and \texttt uses Courier. The courier package changes only the monospace family. For code listings, see monospace fonts for code listings.
Change the font with a package (pdfLaTeX)
Use this when you compile with pdfLaTeX, the default on Overleaf, and want a different typeface for the whole document.
Load the package in the preamble, together with \usepackage[T1]{fontenc} for proper accented characters and hyphenation:
\documentclass{article}\usepackage[T1]{fontenc}\usepackage{newtxtext,newtxmath} % Times-style text and maths\begin{document}Times-style text and maths: $\int_0^1 x^2\,dx = \frac{1}{3}$.\end{document}| Package | Look | Engine | Maths font |
|---|---|---|---|
lmodern | Latin Modern, a scalable Computer Modern | pdfLaTeX | Yes, Computer Modern |
newtxtext,newtxmath (newtx) | Times-style serif | pdfLaTeX | Yes, matching |
mathptmx | Times-style serif | pdfLaTeX | Yes, no bold maths |
tgtermes / tgheros | TeX Gyre Times and Helvetica clones | pdfLaTeX | No, text only |
helvet (load as [scaled=0.92]{helvet}) | Helvetica-style sans for \textsf | pdfLaTeX | No, text only |
courier | Courier for \texttt | pdfLaTeX | No, text only |
libertinus | Libertinus serif and sans | pdfLaTeX, XeLaTeX, LuaLaTeX | With XeLaTeX or LuaLaTeX; add libertinust1math for pdfLaTeX |
fontspec | Any OpenType or TrueType font | XeLaTeX, LuaLaTeX | Add unicode-math |
The old times package is obsolete: it changes the text but leaves the maths in Computer Modern. Use newtx or mathptmx instead.
To combine a Times-style body with Helvetica and Courier:
\documentclass{article}\usepackage[T1]{fontenc}\usepackage{mathptmx} % Times-style text and maths\usepackage[scaled=0.92]{helvet} % Helvetica-style sans, scaled to match\usepackage{courier} % Courier-style monospace\begin{document}This is in Times New Roman, which is the default font for this document.
This part remains in Times, but \textsf{this part is in Helvetica}.
Here is some code in Courier: \texttt{int main() \{ return 0; \}}.\end{document}
Overleaf’s guide to font sizes, families and styles covers more packages.
Use any font with fontspec (XeLaTeX and LuaLaTeX)
Use this when you need a specific font, such as a university’s required typeface or a system font.
fontspec loads OpenType and TrueType fonts by name. It only works with XeLaTeX or LuaLaTeX; on Overleaf, switch the compiler through the gear icon or the File menu, then Compiler.
\documentclass{article}\usepackage{fontspec}\setmainfont{TeX Gyre Termes} % Times-like serif\setsansfont{TeX Gyre Heros} % Helvetica-like sans\setmonofont{TeX Gyre Cursor} % Courier-like monospace\begin{document}Main text in TeX Gyre Termes, \textsf{sans text in TeX Gyre Heros}and \texttt{code in TeX Gyre Cursor}.\end{document}Result: a document set in fonts that ship with TeX Live. It compiles on Overleaf, and locally with LuaLaTeX; see the common errors below if XeLaTeX can’t find them.
On your own computer, you can name any installed font. This example uses fonts that come with macOS:
\documentclass{article}\usepackage{fontspec}\setmainfont{Arial}\setsansfont{Helvetica}\setmonofont{Courier New}\begin{document}This is in Arial, which is the default font for this document.
This text is in Arial, but \textsf{this part is in Helvetica}.
Here is some code in Courier: \texttt{int main() \{ return 0; \}}.\end{document}
- Helvetica isn’t installed on Windows or available on Overleaf; use TeX Gyre Heros or Arial there.
- Overleaf has a long list of fonts you can name directly, including Arial, Times New Roman and Courier New. See which fonts Overleaf supports with fontspec.
- Font features go in the preamble:
\setmainfont{TeX Gyre Pagella}[Numbers=OldStyle]gives old-style figures.
Change the font of headings
Use this when headings should look different from the body text.
The titlesec package controls section heading fonts:
\usepackage{titlesec}\titleformat{\section}{\Large\bfseries\sffamily}{\thesection}{1em}{}\sectionis the heading level to change; repeat for\subsectionand others.\Large\bfseries\sffamilysets size, weight and family.\thesectionprints the number, and1emis the gap before the title.
Bold, italic, small caps and other styles
Use these commands for individual words:
| Command | Effect |
|---|---|
\textbf{...} | Bold |
\textit{...} | Italic |
\textsl{...} | Slanted |
\textsc{...} | Small caps (if the font has them) |
\emph{...} | Emphasis, italic by default |
\underline{...} | Underline |
\MakeUppercase{...} / \MakeLowercase{...} | Change case |
\sout{...} (ulem package) | Strikethrough |
Load ulem as \usepackage[normalem]{ulem}. Without [normalem], it redefines \emph to underline instead of italicise:

Which method should you use?
| Method | Best for | Works with |
|---|---|---|
| Class option or size commands | Text size | All engines |
\renewcommand{\familydefault} | Whole document in sans or mono | All engines |
| Font package | A standard typeface with matching maths | pdfLaTeX (some also XeLaTeX/LuaLaTeX) |
fontspec | Any installed or required font | XeLaTeX, LuaLaTeX |
Common errors
Fatal Package fontspec Error: The fontspec package requires either XeTeX or LuaTeX: you’re compiling with pdfLaTeX. Switch to XeLaTeX or LuaLaTeX, or use a font package.The font "…" cannot be found: the font isn’t installed on that system. On a local XeLaTeX install, fonts that come with TeX Live may not be found by name; compile with LuaLaTeX or install the font in your system.Unused global option(s): [sans]:sansisn’t a class option. Use\renewcommand{\familydefault}{\sfdefault}.\emphtext is underlined: loadulemwith[normalem].- Class option
14ptignored: useextarticleor another class that supports it.
If you’re moving the document to Word afterwards, see fonts after converting LaTeX to Word, where a reference document sets the Word fonts. For long formulas in your new font, see line breaks in LaTeX equations. More formatting guides are in the LaTeX guides.