如何通过自定义类在标题页中制作斜体 Georgia 字体?

如何通过自定义类在标题页中制作斜体 Georgia 字体?

我正在尝试基于报告类构建一个 LaTeX 类,以复制我组织的品牌 Word 模板。除了一个方面,我已经解决了大部分问题。当报告确定作者时,我们的样式指南要求标题页包含 14 号斜体 Georgia 字体的“由 [姓名] 编写”。出于某种原因,我无法在标题页中同时使用斜体和 Georgia。

如果标题页上的字体是 Georgia,它会忽略斜体。如果我不坚持使用 Georgia,我可以将其设置为斜体。这并不是说字体的斜体版本不可用——文本的主体也是 Georgia,我可以在那里很好地使用斜体——问题只出现在标题页中。我尝试了几种不同的斜体命令,并在调用之前或之后调用它们\fontfamily{},但当标题页上的字体是 Georgia 时,它们都不起作用。

以下是该类的 MWE:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass.cls}

% MWE to demonstrate italicizing issue with Georgia font in title page

% Call packages required to make the title page work
\RequirePackage[T1]{fontenc}
\RequirePackage{helvet}
\RequirePackage{color}
\RequirePackage{setspace}
\RequirePackage{ragged2e}


\RequirePackage{anyfontsize}
\RequirePackage{graphicx}
\RequirePackage{tikz}
\RequirePackage{ulem}


% Define colors
\definecolor{titlegray}{RGB}{60,60,59}



\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}} % Pass any other options through to the report class
\ExecuteOptions{hidelinks}
\ProcessOptions\relax % Run the options
\LoadClass{report} % Now load the report class as a base

\def\subtitle#1{\gdef\@subtitle{#1}}

% Redefine \maketitle to produce the CFPB report title page

\renewcommand{\maketitle}{
\begin{titlepage} % Enclose in a titlepage environment
\normalem
 % All the text in this environment is sans-serif/Arial
\sffamily

%Bold agency name and date; the \textls increases the cerning slightly to match the Arial Bold font
\textls[100]{\textbf{\sffamily\small\MakeUppercase{Bureau of Agency Departments \ \ $|$ \ \ \@date}}}

% Then the main title 1.75" down in size 38 font
\vspace{1.31in}
{\fontsize{38}{40}\selectfont \@title \par}

%Subtitle 1/2" below that in size 16 font
\vspace{.5in}
{\fontsize{16}{18}\sffamily\selectfont \@subtitle \par}

%Authors 1/2" below that in size 16 italic, serif font
\vspace{0.5in}
 {\itshape\fontsize{16}{18}\fontfamily{georgia}\selectfont \textit{\@author} \par}
 \newpage
\end{titlepage}
}

% All classes have to define \normalsize 
\renewcommand{\normalsize}{\fontsize{12}{16}\selectfont}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9in}



% The microtype package is needed to typeset the title page correctly, but needs \normalsize to be defined before it's called, so calling now, instead of with the other required packages.
\RequirePackage{microtype}

% Main doc uses georgia throughout
\fontfamily{georgia}\selectfont

以下是一份文档的 MWE

\documentclass{myclass}
\usepackage[top=1in,left=1in,bottom=1in,right=1in]{geometry}

\title{A Report}
\author{Prepared by The Preparors}
\subtitle{Great Report Series \#5}
\date{April 2023}


\begin{document}

\maketitle
This is some Georgia Text

\textit{This is some italic Georgia text}

\end{document}

如果重要的话,我正在 Overleaf 中运行 pdfLaTeX。

答案1

(此处感谢 Ulrike Fischer 的评论;如果他们发表答案,我很乐意接受他们的答案)

我仍然不清楚为什么非全局字体声明允许我将作者行设置为 Georgia 或斜体,但不能同时使用两者。但是,对于遇到类似问题的人来说,解决方法是重新定义默认字体,而不仅仅是在类文件中放置字体开关。

这里的问题是,使用 为正文声明 Georgia 字体\fontfamily{georgia}\selectfont可能会被各种环境覆盖。在类中声明主字体的更好方法是使用\renewcommand\rmdefault{georgia}。然后,\fontfamily{georgia}\selectfont在定义的 author 行中\titlepage省略 会导致斜体被尊重。

因此该类的 MWE 变为:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass.cls}

% MWE to demonstrate italicizing issue with Georgia font in title page

% Call packages required to make the title page work
\RequirePackage[T1]{fontenc}
\RequirePackage{helvet}
\RequirePackage{color}
\RequirePackage{setspace}
\RequirePackage{ragged2e}


\RequirePackage{anyfontsize}
\RequirePackage{graphicx}
\RequirePackage{tikz}
\RequirePackage{ulem}


% Define colors
\definecolor{titlegray}{RGB}{60,60,59}



\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}} % Pass any other options through to the report class
\ExecuteOptions{hidelinks}
\ProcessOptions\relax % Run the options
\LoadClass{report} % Now load the report class as a base

\def\subtitle#1{\gdef\@subtitle{#1}}

% Redefine \maketitle to produce the CFPB report title page

\renewcommand{\maketitle}{
\begin{titlepage} % Enclose in a titlepage environment
\normalem

%Bold agency name and date; the \textls increases the cerning slightly to match the Arial Bold font
\textls[100]{\textbf{\sffamily\small\MakeUppercase{Bureau of Agency Departments \ \ $|$ \ \ \@date}}}

% Then the main title 1.75" down in size 38 font
\vspace{1.31in}
{\fontsize{38}{40}\sffamily\selectfont \@title \par}

%Subtitle 1/2" below that in size 16 font
\vspace{.5in}
{\fontsize{16}{18}\sffamily\selectfont \@subtitle \par}

%Authors 1/2" below that in size 16 italic, serif font
\vspace{0.5in}
 {\itshape\fontsize{16}{18}\textit{\@author} \par}
 \newpage
\end{titlepage}
}

% All classes have to define \normalsize 
\renewcommand{\normalsize}{\fontsize{12}{16}\selectfont}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9in}



% The microtype package is needed to typeset the title page correctly, but needs \normalsize to be defined before it's called, so calling now, instead of with the other required packages.
\RequirePackage{microtype}

% Main doc uses georgia throughout
\renewcommand\rmdefault{georgia}

相关内容