指定 PDFlaTeX 的斜體字體

指定 PDFlaTeX 的斜體字體

對於我的 PDFlaTeX 文檔,我想在正文中使用 roboto 平板燈,在標題中使用 roboto。我遇到以下問題:

  1. 如果我將 Roboto Plate Light 設定為主要字體,那麼我不知道如何僅將 Roboto 設定為標題。我嘗試使用 \sffamily 來做到這一點,但它不起作用。我得到的是一份完全用 Roboto Plate Light 編寫的文檔(包括標題)
  2. roboto 平板燈的缺點是它沒有斜體 - 如何指定與 \textit 和 \emph{} 一起使用的不同字體(例如 roboto)?

這裡有一個例子:

\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}

答案1

明確載入字體定義文件,以便您隨後可以添加一些聲明。

對於部分標題,請指定Roboto-LF係列。

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

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

\makeatletter
\input{\encodingdefault RobotoSlab-TLF.fd}
\DeclareFontShape{\encodingdefault}{\familydefault}{l}{it}{
 <->ssub*Roboto-TLF/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}

在此輸入影像描述

答案2

這需要切換到 LuaLaTeX,並且可能不適用於所有情況。但這與原始問題充分相關:

使用fontspec語法,您可以建立混合字體系列。常規字體可以是一個文件,粗體可以來自不同的系列,斜體可以來自不同的系列。您可以透過請求特定檔案名稱來設定它(首選 Open Type,其次選擇 TrueType)。像這樣:

% !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}

不過,我無法讓它與該\titleformat*命令一起工作。

您不使用包fontencinputenc.在某些情況下(不是全部)您不通過 加載字體\usepackage{font}機器人文本

相關內容