1

I'm trying to customise a Beamer template and while it's easy to change the font for the entire presentation using \setmonofont{} and \setsansfont{}, I can't figure out how I can change the font of a single element. For instance I'd like to use different fonts for title and author in the title page. \setbeamerfont{} seems to allow modifying properties of a font in each section but not the font itself?

UPDATE So I just discovered \begingroup and \endgroup commands. If I wrap the section I want into a group then I can apply a new setmonofont{} inside the group and achieve what I want. However, this looks like a hack and I prefer if all the font changes were made in the font drx file.

  • It’s a bit late to post a full answer, but \setbeamerfont supports family=, which lets you change the font family. – Davislor Feb 9 at 13:51
  • Isn't that limited to internal fonts? Is there a way to use external fonts (with XeLaTeX and fontspec) similar to setmonofont{} and \setsansfont{} ? – Milad Feb 9 at 13:58
3

You can do this with \setbeamerfont{...}{family=}, or \setbeamerfont{...}{family*=} for legacy NFSS font families.

Here is an example that declares a \newfontfamily with the modern toolchain and unicode-math. It requires LuaLaTeX or XeLaTeX.

\documentclass[noamssymb,
               professionalfonts,
               xcolor={HTML, svgnames, Svgnames}
              ]{beamer} % Loads several other packages, including amsthm and geometry.
\usepackage[math-style=ISO]{unicode-math}

\geometry{paperwidth = 10cm} % Appropriate width for a MWE on TeX.SX.

\defaultfontfeatures{ Scale = MatchLowercase }
\newfontfamily\avantgarde{TeX Gyre Adventor}[Ligatures=Common]
\setbeamerfont{frametitle}{family=\avantgarde}

\begin{document}
\begin{frame}
  \frametitle{There Is No Largest Prime Number}
  \framesubtitle{The proof uses \textit{reductio ad absurdum}.}

  \begin{theorem}
    There is no largest prime number.
  \end{theorem}
  \begin{proof}
    \begin{enumerate}
      \item Suppose $p$ were the largest prime number.
      \item Let $q$ be the product of the first $p$ numbers.
      \item Then $q+1$ is not divisible by any of them.
      \item But $q + 1$ is greater than $1$, thus divisible by some prime
                number not in the first $p$ numbers.\qedhere
    \end{enumerate}
  \end{proof}
\end{frame}
\end{document}

Font sample with Adventor

In a real document, you would want to set up a few extra \setmathfont[range=...] commands to tweak things like the math letters and QED symbol. I didn’t do that here, to keep this example minimal, so the font selection will look pretty strange.

And here is an example compatible with PDFLaTeX:

\documentclass[xcolor={HTML, svgnames, Svgnames}
              ]{beamer} % Loads several other packages, including amsthm and geometry.
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc} % The default since 2018.

\geometry{paperwidth = 10cm} % Appropriate width for a MWE on TeX.SX.

\setbeamerfont{frametitle}{family*=qag} % TeX Gyre Adventor

\begin{document}
\begin{frame}
  \frametitle{There Is No Largest Prime Number}
  \framesubtitle{The proof uses \textit{reductio ad absurdum}.}

  \begin{theorem}
    There is no largest prime number.
  \end{theorem}
  \begin{proof}
    \begin{enumerate}
      \item Suppose $p$ were the largest prime number.
      \item Let $q$ be the product of the first $p$ numbers.
      \item Then $q+1$ is not divisible by any of them.
      \item But $q + 1$ is greater than $1$, thus divisible by some prime
                number not in the first $p$ numbers.\qedhere
    \end{enumerate}
  \end{proof}
\end{frame}
\end{document}

Type1 font sample

In this case, you would need to pass the NFSS family name to family*=. The documentation of the font tells us that the filenames are qagr, qagb, qagri and qagbi, so the common prefix of the font family is qag. (This made sense at the time. Back when the lowest common denominator of a file system supported only eight-letter filenames, and every variant font face needed its own filename, family names needed to be cryptic. GUST chose the prefix q for its TeX Gyre fonts because it was nearly unused, and Adventor is a clone of Avant Garde Gothic.)

Some legacy font packages define an NFSS family name that might work with family=. You would need to check the documentation.

You can also select a font family within an element, e.g. \frametitle{\avantgarde There is no Largest Prime Number}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.