PDFlaTeXの斜体フォントを指定する

PDFlaTeXの斜体フォントを指定する

PDFlaTeX ドキュメントでは、メイン テキストに roboto slab light を使用し、タイトルに roboto を使用したいと考えています。次のような問題が発生しています。

  1. roboto slab light をメインフォントとして設定した場合、roboto をタイトルのみに設定する方法がわかりません。\sffamily でそれを試してみましたが、うまくいきませんでした。私が得るのは、roboto slab light で完全に書かれた文書です (タイトルを含む)
  2. roboto slab light の欠点は斜体がないことです。\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、ハイブリッド フォント ファミリを作成できます。通常のフォントは 1 つのファイルで、太字は別のファミリから、斜体は別のファミリから使用できます。特定のファイル名を要求することで設定します (Open Type が優先され、TrueType が 2 番目に選択されます)。次のようになります。

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

fontencパッケージまたは を使用しませんinputenc。場合によっては (すべてではありません)、 経由でフォントをロードしません\usepackage{font}ロボットテキスト

関連情報