0

I would like to switch up between the two font types: Lato and Raleway in one body of text. I spent some time to search for answer but no success. If I set one as default cannot change the selected words to the other.

\documentclass{article}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
% \usepackage[default]{raleway} Set raleway as default
% \usepackage[default]{lato} Set lato as default
\begin{document}
        {\fontfamily{raleway}\selectfont \lipsum[1]}
    {\fontfamily{lato}\selectfont \lipsum[1]}

\end{document}

These are the answers I looked up but could not apply:

How to change the font for selected words in LaTeX document

How do I use a particular font for a small section of text in my document?

Reza
  • 319

2 Answers2

2

Loading raleway without any options will make it the default sans serif font anyway, so you can use {\sffamily ...} or \textsf{...}.

For lato, you can select \latofamily manually:

\documentclass{article}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage{raleway}
\usepackage{lato}
\begin{document}

{\sffamily This is Raleway. \lipsum[1]}

{\fontfamily{\latofamily}\selectfont This is Lato. \lipsum[1]}

\end{document}

enter image description here

imnothere
  • 14,215
1

Unless you are constrained to legacy fonts, it is much easier and more flexible to use the modern toolchain with fontspec package and system fonts, and compiling with xelatex or lualatex. You can define as many (or as few) font switches as you need. OpenType font features become available also.

switching fonts

(Fonts coloured to highlight the switching.)

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fontspec}
\newfontfamily{\fraleway}{Raleway}[Colour=blue]
\newfontfamily{\flato}{Lato}[Colour=red]
\newcommand\parnum{5}
\begin{document}

\sffamily This is default sans. \lipsum[\parnum]

\fraleway This is Raleway. \lipsum[\parnum]

\flato This is Lato. \lipsum[\parnum]

\normalfont\sffamily This is back to default font. \lipsum[\parnum] \end{document}

To set a font as the sans font for a document, the \setsansfont{...} command is used.

Here, Raleway is made the default sans:

default Raleway

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fontspec}
\setsansfont{Raleway}
\newfontfamily{\fraleway}{Raleway}[Colour=blue]
\newfontfamily{\flato}{Lato}[Colour=red]
\newcommand\parnum{5}
\begin{document}

\sffamily This is default sans. (Raleway) %{\tiny\fontname\font\ } \lipsum[\parnum]

\fraleway This is Raleway. %{\tiny\fontname\font\ } \lipsum[\parnum]

\flato This is Lato. %{\tiny\fontname\font\ } \lipsum[\parnum]

\normalfont\sffamily This is back to default font. %{\tiny\fontname\font\ } \lipsum[\parnum] \end{document}

Cicada
  • 10,129