使用 fontspec 包更改字体大小的推荐方法是什么?
我找到了几种看似可行的方法,但过程中出现了一些意想不到的行为。我做错了什么?
我使用 切换字体大小,\fontsize{30pt}{36pt}\selectfont
并基于此定义命令。出乎意料的是,随着应用不同的开关,字体会在不同的变体之间切换。出乎意料。请告诉我为什么会发生这种情况。
我正在编写文档XeLaTeX
。在我的平均能量损失我使用该Zapfino
字体是因为当意外行为发生时我正在尝试使用它。
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{fontspec}
%% with fontspec package
%% How do you set font size inside the preamble?
%%
%% IN PREAMBLE
%% 1. SUCCESS
\setmainfont[Variant = 1, Ligatures = {Common,Rare}]{Zapfino}%
%% \setmainfont[SizeFeatures={Size=20}]{Zapfino}% appears to work...
%% % The option SizeFeatures is not intended to set a size. It is intended to set features that are activated only for some font sizes.
%%
%% 2. CRASHES
%% \setmainfont[Variant = 1,
%% SizeFeatures={Size=20}, # why doesn't this crash above?
%% Ligatures = {Common,Rare}
%% ]{Zapfino}%
%%
%% 3. NO EFFECT
%% \fontsize{20pt}{24pt}\selectfont
%%
\begin{document}
%% %% How do you switch font size inside the document?
%% Options set after \begin{document}
%% 4. SUCCESS
%% \fontspec[Ligatures={Common,Rare}]{Zapfino}%
%% \fontsize{20pt}{24pt}\selectfont
%%
%% 5. ERROR.
%% \addfontfeature{Size=20}
%%
%% 6. CRASHES
%% \addfontfeature{SizeFeatures={Size=20}}
%%
%% 7. SUCCESS
\newcommand{\smallfont}[1]{%
\fontspec[Ligatures={Common,Rare}]{Zapfino}%
\fontsize{10pt}{12pt}\selectfont #1}
\newcommand{\normfont}[1]{%
\fontspec[Ligatures={Common,Rare}]{Zapfino}%
\fontsize{20pt}{24pt}\selectfont #1}
\newcommand{\bigfont}[1]{%
\fontspec[Ligatures={Common,Rare}]{Zapfino}%
\fontsize{30pt}{36pt}\selectfont #1}
\fontsize{30pt}{36pt}\selectfont
Big
\fontsize{20pt}{24pt}\selectfont
and
\fontsize{10pt}{12pt}\selectfont
Small
\bigfont{Big} \normfont{and} \smallfont{Small}
Why are different variants of the font selected?
\end{document}
作为埃格尔在评论和答案中进一步解释道,“通过 SizeFeatures={Size=20},您可以告知仅在 20pt 大小下使用 Zapfino。”插图:
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Variant = 1, Ligatures = {Common,Rare}]{Zapfino}%
\setmainfont[SizeFeatures={Size=20}]{Zapfino}%
\begin{document}
\fontsize{30pt}{36pt}\selectfont
Big is not Big
\fontsize{20pt}{24pt}\selectfont
20pt is 20pt
\fontsize{10pt}{12pt}\selectfont
Small is not Small
\end{document}
答案1
首先,让我们放弃这个SizeFeatures
选择。如果你声明
\setmainfont{Zapfino}[
SizeFeatures={Size=20},
% ... other options ...
]
你基本上是在告诉大家使用 20 号尺寸,而不考虑上下文。如果我这样做并要求\fontsize{30}{36}\selectfont
,我会得到
LaTeX Font Warning: Font shape `EU1/Zapfino(0)/m/n' in size <30> not available
(Font) size <20> substituted on input line 22.
第二个问题。当你这样做时\fontspec{<font>}[<options>]
,你正在声明一个新字体。就你的情况来说,Variant=1
是没有继承的。
您不需要做任何特别的事情来改变尺寸:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Zapfino}[
Variant = 1,
Ligatures = {Common,Rare},
]
\newcommand{\smallfont}[1]{{%
\fontsize{10pt}{12pt}\normalfont #1%
}}
\newcommand{\normfont}[1]{{%
\fontsize{20pt}{24pt}\normalfont #1%
}}
\newcommand{\bigfont}[1]{{%
\fontsize{30pt}{36pt}\normalfont #1%
}}
\begin{document}
\fontsize{30pt}{36pt}\selectfont
Big
\fontsize{20pt}{24pt}\selectfont
and
\fontsize{10pt}{12pt}\selectfont
Small
\normalsize
\bigfont{Big} \normfont{and} \smallfont{Small}
Why are different variants of the font selected?
\end{document}