在 XeLaTeX 中设置字体大小

在 XeLaTeX 中设置字体大小

先前的问题在使用 fontspec 时,人们一直在寻求一种直接的方式来指定新字体系列的字体大小(例如,以磅为单位)。可能需要这样做的原因之一是,一些期刊要求各种文本使用特定的字体大小 — — 例如 9.5pt 或 11.5pt,而大多数文档类都不支持这些字体大小。

以前的热门答案建议使用Scale,据说它可以简单地作为输入到文档类的字体大小的一个因素,以便控制特定的字体大小。例如,如果10pt为文档类和新字体系列指定Scale=1.2,那么应该期望该字体以 12 点大小显示。

当要缩放的字体是主字体时,以这种方式使用Scale效果很好。但是,当涉及不同的字体时,Scale=1.0会产生与 不同的大小的字体Scale=MatchLowercase。对于上面的示例,如果文档字体大小为 10pt,我假设使用Scale=MatchLowercase而不是 时,此新字体也将是 10pt Scale=1.0。但是,我对 fontspec 或字体指标的内部工作原理了解不够,不知道这是否正确。

此示例的 mwe 如下:

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{DejaVu Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\dejavusansten[Scale=1.0]{DejaVu Sans}
\newfontfamily\dejavusanstwelve[Scale=1.2]{DejaVu Sans}

\begin{document}

   This is a test of DejaVu Serif, as mainfont\\

   {\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}\\

   {\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}\\


   \textsf{This is a test of DejaVu Sans, MatchLowercase}\\

   {\dejavusansten This is a test of DejaVu Sans, Scale=1.0}\\

   {\dejavusanstwelve This is a test of DejaVu Sans, Scale=1.2}\\

\end{document}

输出: mwe 的输出

在此示例中,使用了两种 DejaVu 字体,因此具有相同值的不同字体Scale看起来大小大致相同。但是,当字体完全不同时,情况并非如此。下面提供了上述 mwe 的修改版本,使用 Latin Modern Sans 代替 DejaVu Sans:

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\lmsansten[Scale=1.0]{Latin Modern Sans}
\newfontfamily\lmsanstwelve[Scale=1.2]{Latin Modern Sans}

\begin{document}

   This is a test of DejaVu Serif, as mainfont\\

   {\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}\\

   {\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}\\


   \textsf{This is a test of Latin Modern Sans, MatchLowercase}\\

   {\lmsansten This is a test of Latin Modern Sans, Scale=1.0}\\

   {\lmsanstwelve This is a test of Latin Modern Sans, Scale=1.2}\\

\end{document}

输出: 第二个 mwe 的输出

在这个例子中,MatchLowercaseLatin Modern Sans 的版本看起来与 DejaVu Serif 主字体大小相同,而版本Scale=1.0看起来要小得多。

我的问题是,使用Scale这种方法来设置精确的字体大小是否真的是一种合理的方法。如果是这样,那么是否可以假设,即使第二种字体在数值相等的比例下“看起来”大小不同,但实际上字体点数相同?也欢迎对字体指标和/或字体规格的相关方面进行良好的解释。

答案1

使用SizeFeature而不是Scale。最后一行显示两条 10pt 线具有相同的高度:

\documentclass[10pt]{article}
\usepackage{fontspec}
\parindent=0pt
\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[SizeFeatures={Size=10}]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[SizeFeatures={Size=12}]{DejaVu Serif}

\newfontfamily\lmsansten[SizeFeatures={Size=10}]{Latin Modern Sans}
\newfontfamily\lmsanstwelve[SizeFeatures={Size=12}]{Latin Modern Sans}

\begin{document}
This is a test of DejaVu Serif, as mainfont\\
{\dejavuseriften This is a test of DejaVu Serif, Size=10\\}
{\dejavuseriftwelve This is a test of DejaVu Serif, Size=12\\}

This\textsf{This is a test of Latin Modern Sans, MatchLowercase\\}% compare 
%loercase
{\lmsansten This is a test of Latin Modern Sans, Size=10\\}
{\lmsanstwelve This is a test of Latin Modern Sans, Size=12\\}

\makebox[0pt][l]{This is a test of DejaVu Serif, as mainfont}%
{\lmsansten This is a test of Latin Modern Sans, Size=10\\}

\end{document}

在此处输入图片描述

答案2

我的建议是不要Scale这样使用。您会注意到,您正在使用 定义一个“新字体系列” \newfontfamily,因此期望它直觉地认为这个“新”系列实际上不是新的是不合理的。

也许更好的方法是使用常规的 LaTeX2e 字体命令\DeclareTextCommand

\documentclass[10pt]{article}
\parindent 0pt

\usepackage{fontspec,multicol,xcolor}% xcolor is just for fun...

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\dejavusansten[Scale=1.0]{Latin Modern Sans}
\newfontfamily\dejavusanstwelve[Scale=1.2]{Latin Modern Sans}

\DeclareTextCommand{\djx}{EU1}{\rmfamily\fontsize{10}{12}\selectfont}
\DeclareTextCommand{\djxii}{EU1}{\rmfamily\fontsize{12}{14.4}\selectfont}

\DeclareTextCommand{\lmsx}{EU1}{\sffamily\fontsize{10}{12}\selectfont}
\DeclareTextCommand{\lmsxii}{EU1}{\sffamily\fontsize{12}{14.4}\selectfont\addfontfeature{Color=purple}}

\DeclareTextCommand{\textdjx}{EU1}[1]
  {{\rmfamily\fontsize{10}{12}\selectfont #1}}
\DeclareTextCommand{\textdjxii}{EU1}[1]
  {{\rmfamily\fontsize{12}{14.4}\selectfont #1}}

\DeclareTextCommand{\textlmsx}{EU1}[1]
  {{\sffamily\fontsize{10}{12}\selectfont #1}}
\DeclareTextCommand{\textlmsxii}{EU1}[1]
  {{\sffamily\fontsize{12}{14.4}\selectfont #1}}


\begin{document}

\section*{`Scale' vs `fontsize'}

\begin{multicols}{2}
  This is a test of DejaVu Serif, as mainfont

  {\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}

  {\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}

  \columnbreak

  This is a test of DejaVu Serif, as mainfont

  {\djx This is a test of DejaVu Serif, at 10pt}

  {\djxii This is a test of DejaVu Serif, at 12pt}
\end{multicols}

\begin{multicols}{2}
  \textsf{This is a test of Latin Modern Sans, MatchLowercase}

  {\dejavusansten This is a test of Latin Modern Sans, Scale=1.0}

  {\dejavusanstwelve This is a test of Latin Modern Sans, Scale=1.2}

  \columnbreak

  \textsf{This is a test of Latin Modern Sans, as mainfont}

  {\lmsx\addfontfeature{Color=blue}%
    This is a test of Latin Modern Sans, at 10pt}

  {\lmsxii This is a test of Latin Modern Sans, at 12pt}
\end{multicols}


\section*{rmfamily vs sffamily}

\begin{multicols}{2}
  This is a test of DejaVu Serif, as mainfont

  {\djx This is a test of DejaVu Serif, at 10pt}

  {\djxii This is a test of DejaVu Serif, at 12pt}

  \columnbreak

  \textsf{This is a test of Latin Modern Sans, as mainfont}

  {\lmsx\addfontfeature{Color=blue}%
    at This is a test of Latin Modern Sans, at 10pt}

  {\lmsxii This is a test of Latin Modern Sans, at 12pt}
\end{multicols}

\end{document}

相关内容