3

For my PDFlaTeX document I`d like to use roboto slab light for the main text and roboto in titles. I am having the following problems:

  1. if I set roboto slab light as main font, then I do not know how to set roboto for titles only. I try to do that with \sffamily, but it does not work. What I get is a document written completely in roboto slab light (incl. titles)
  2. roboto slab light is that it does not have italics - how to specify a different font (e.g. roboto) to be used with \textit and \emph{}?

Here an example:

\documentclass[a4paper, 12pt, english]{report}
\usepackage[rm, light]{roboto} %this makes roboto slab light the main document font
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{titling}
\titleformat*{\section}{\sffamily\Large} %with sffamily I try to set roboto regular as section title font

\begin{document}
\section{I need to be in roboto font}
I am normal text and need to be in roboto slab light font.
\textit{I am in italics and need a different font, e.g. roboto}
\end{document}
2

Explicitly load the font definition file, so you'll be able to add some declarations afterwards.

For the section titles, specify the Roboto-LF family.

\documentclass{report}
\usepackage[T1]{fontenc}

\usepackage[rm,light]{roboto}
\usepackage{titlesec}

\makeatletter
\input{\encodingdefault RobotoSlab-LF.fd}
\DeclareFontShape{\encodingdefault}{\familydefault}{l}{it}{
 <->ssub*Roboto-LF/l/it
}{}
\makeatother

\titleformat*{\section}{\fontfamily{Roboto-LF}\fontseries{m}\Large}

\begin{document}

\section{I need to be in roboto font}


I am normal text and need to be in roboto slab light font.
\textit{I am in italics and need a different font, e.g. roboto}
\end{document}

enter image description here

2

This requires a switch to LuaLaTeX, and might not work for every situation. But is is sufficiently related to the original question:

Using fontspec syntax, you can create a hybrid font family. The regular font can be one file, the bold can be from a different family, and the italic can be from a different family. You set it up by requesting the specific file names (Open Type preferred, TrueType second choice). Like this:

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8
\documentclass{report}
\usepackage{fontspec}
% Note that \usepackage{roboto} is not used here.
% But you must the package installed, at least its TrueType fonts.
\setmainfont[ %
  ItalicFont=Roboto-LightItalic.ttf, % or whatever
  BoldFont=Roboto-Regular.ttf, % uses regular in place of bold
]{RobotoSlab-Light.ttf} % main font
%
\begin{document}
\section{\textbf{I need to be in roboto font}}
I am normal text and need to be in roboto slab light font.
\textit{I am in italics and need a different font, e.g. roboto}
\end{document}

I was not able to get it to work with the \titleformat* command, though.

You do not use packages fontenc or inputenc. In some cases (not all) you do not load the fonts via \usepackage{font}. roboto text

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.