对于我的一份文档,我在常规文本中使用了 OldStyle 数字。对于数学,我使用 Lining 数字。对于表格材料,如果这些数字与数学相关,我想使用等宽的 Lining 数字(我使用包S
中的列类型来格式化它们siunitx
)。但是,到目前为止,我还没能让这最后一部分发挥作用。我正在使用 XeLaTeX 和包mathspec
。
在下面的 MWE 中,我首先设置主字体(阿莱格雷亚·桑斯)和默认(非等宽)数学字体(顺便说一句,可能与我使用的这个问题无关Fira Sans表示希腊字母,但其他字符则来自 Alegreya Sans。
在我的部分解决方案中(如 MWE 所示),我告诉siunitx
将数字视为文本,然后在开始材料之前切换主字体tabular
。通过将其放在花括号中并在标题前关闭它们,标题中的数字看起来不错(OldStyle,非等宽字体)。但是,正如您在第一列中看到的那样,这显然也会改变第一列中的数字,我希望保留 OldStyle 和非等宽字体。
有没有办法简单地在文本中的某个地方切换数学字体?mathspec
手册(和我的经验)表明,使用\setmathsfont{}
在序言之外使用不起作用。我发现这和这个答案它使用\setmathfont[version=something]
,但需要unicode-math
包,而我不需要包(并且这似乎在我的文档中弊大于利,因为我不打算在排版数学时使用 Unicode 符号)。
妇女权利委员会:
\documentclass{scrartcl}
\usepackage[]{mathspec}
\setmainfont[Numbers=OldStyle,BoldFont={Alegreya Sans Bold}]{Alegreya Sans}
\setmathsfont(Greek)[Numbers={Lining},BoldFont={Fira Sans Medium},Scale=0.90]{Fira Sans Book}
\setmathsfont(Digits,Latin)[Numbers={Lining},BoldFont={Alegreya Sans Bold}]{Alegreya Sans}
\setmathsf[Numbers={Lining},BoldFont={Alegreya Sans Bold}]{Alegreya Sans}
% The following is needed to get units typeset correctly when using \SI{}{}
\setmathrm[Numbers={Lining},BoldFont={Alegreya Sans Bold}]{Alegreya Sans}
\usepackage{siunitx}
\begin{document}
Table~\ref{tab:monospaced} should show monospaced, lining numbers. The
following numbers should not be monospaced and should be OldStyle:
0123456789. Testing siunitx: \SI{123}{mm}.
\begin{table}
\centering
{
\sisetup{mode=text}
\setmainfont[Numbers={Monospaced,Lining},BoldFont={Alegreya Sans Bold}]{Alegreya Sans}
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
}
\caption{This table should be correctly formatted. The math/siunitx
numbers should be Monospaced and Lining. These numbers in the
caption should be OldStyle: 0123456789.}
\label{tab:monospaced}
\end{table}
To verify the fonts aren't changed permanently,
Table~\ref{tab:defaultFont} shows the same table, but with default
fonts settings.
\begin{table}
\centering
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
\caption{A table with the default font settings for comparison.
These numbers in the caption should be OldStyle and not
Monospaced: 0123456789.}
\label{tab:defaultFont}
\end{table}
The following numbers should not be monospaced and should be OldStyle:
0123456789.
\end{document}
原始问题提出后添加了以下内容。
根据@Henri Menke 在评论中的建议,我尝试将表格部分包装在一个\addfontfeatures
块中(如fontspec
手册第 7.3 节中所做的那样)。查看输出,这会导致第 1 列中出现等宽 OldStyle 数字(不是我想要的,但可以接受)。但是,现在其他列(由格式化)中的数字siunitx
变为 Oldstyle(奇怪!)并且不是等宽的。这可能只是fontspec
手册中提到的未定义行为。
这是表 1 的代码:
\begin{table}
\centering
\sisetup{mode=text}
\addfontfeatures{Numbers={Monospaced,Lining}}{
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
}
\caption{This table should be correctly formatted. The math/siunitx
numbers should be Monospaced and Lining. These numbers in the
caption should be OldStyle: 0123456789.}
\label{tab:monospaced}
\end{table}
为了尝试修复此问题,我还删除了该\sisetup{mode=text}
行。如下所示,这几乎达到了我想要的效果。第一列中的数字是 OldStyle ,但为等宽(不是我想要的,但可以接受),但是,其他(数学)列中的数字是 Lining (我想要的),但不是等宽。所以我的结论是,该\addfontfeatures
行仅影响主字体中的数字,而不影响数学字体中的数字。
\begin{table}
\centering
\addfontfeatures{Numbers={Monospaced,Lining}}{
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
}
\caption{This table should be correctly formatted. The math/siunitx
numbers should be Monospaced and Lining. These numbers in the
caption should be OldStyle: 0123456789.}
\label{tab:monospaced}
\end{table}
答案1
问题
siunitx
覆盖任何其他字体设置,因为它拥有最终决定权。- OP 指定字体的方式
tabular
不兼容,因为它要求数学字体同时为比例衬线和等宽衬线...... - ...并且它们无法改变,因为(根据
fontspec
手册):当在序言中使用 \setmainfont、\setsansfont 和 \setmonofont 时,它们还会在 \mathrm-type 命令中定义要在数学模式中使用的字体。这只发生在序言中,因为 LaTeX 会在处理此阶段后冻结数学字体。fontspec 包还必须在任何数学字体包(例如 euler)之后加载才能成功。
解决方案
尝试了各种方法后,我找到的唯一解决方案是放弃数学模式(主体)按比例排列和数学模式(表格)按等宽排列的冲突要求。最巧妙的办法似乎是放弃按比例排列的要求。
代码可以简化:
最小 MWE:
\setmainfont[Numbers={OldStyle,Proportional},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
\setmathsfont(Greek)[Numbers={Lining},BoldFont={Fira Sans Medium},Scale=0.90]{Fira Sans Book}
\setmathsfont(Digits,Latin)[Numbers={Lining,Monospaced},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
\setmathsf[Numbers={Lining,Proportional},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
% The following is needed to get units typeset correctly when using \SI{}{}
\setmathrm[Numbers={Lining,Monospaced},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
\usepackage[mode=math]{siunitx}
完整 MWE:
\documentclass[oneside,11pt]{article}
\usepackage{mathspec}
\setmainfont[Numbers={OldStyle,Proportional},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
%\setmathsfont(Greek)[Numbers={Lining},BoldFont={Fira Sans Medium},Scale=0.90]{Fira Sans Book}
\setmathsfont(Digits,Latin)[Numbers={Lining,Monospaced},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
\setmathsf[Numbers={Lining,Proportional},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
% The following is needed to get units typeset correctly when using \SI{}{}
\setmathrm[Numbers={Lining,Monospaced},BoldFont={AlegreyaSans-Bold.otf}]{AlegreyaSans-Regular.otf}
\usepackage[mode=math]{siunitx}
\begin{document}
For one of my documents I used proportional OldStyle numerals in regular text:\\
x = 1234567890 111 888\\
x = 0123456789 888 111\\
But math should be proportional lining but as that's impossible we'll settle for monospaced lining:\\
\ensuremath{x = 1234567890 111 888}\\
\ensuremath{x = 0123456789 888 111}
For math I use Lining numbers. For tabular material I would like to use monospaced lining numbers if these numbers are math-related.
Table~\ref{tab:monospaced} should show monospaced, lining numbers. The
following numbers should be proportional and OldStyle:
1234567890. Testing siunitx: \SI{1234567890}{mm}.
\begin{table}[!hb]
\centering
{
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle proportional here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle proportional here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
}
\caption{This table should be correctly formatted. The math/siunitx
numbers should be Monospaced and Lining. These numbers in the
caption should be OldStyle and proportional: 0123456789.}
\label{tab:monospaced}
\end{table}
To verify the fonts aren't changed permanently,
Table~\ref{tab:defaultFont} shows the same table, but with default
fonts settings. Given that OP's requirements and the changes I have made, the OP's typesetting for Table~\ref{tab:defaultFont} should be the same as Table~\ref{tab:monospaced} and the comment `To verify the fonts aren't changed permanently' is obsolete.
\begin{table}[!hb]
\centering
\begin{tabular}{@{} lS[table-format=3]S[table-format=2]S[table-format=2]S[table-format=2.6] @{}}
Text & {People} & {Miles} & {Boats} & {Time}\\
\hline
Something & 999 & 75 & 13 & 12.3456\\
I want OldStyle proportional here 12 & 111 & 54 & 11 & 0.111456\\
I want OldStyle proportional here 99 & 151 & 991 & 22 & 0.987611
\end{tabular}
\caption{A table with the default font settings for comparison.
These numbers in the caption should be OldStyle and Proportional: 0123456789.}
\label{tab:defaultFont}
\end{table}
For one of my documents I used proportional OldStyle numerals in regular text:\\
x = 1234567890 111 888\\
x = 0123456789 888 111\\
But math should be proportional lining but has to be monospaced lining:\\
\ensuremath{x = 1234567890 111 888}\\
\ensuremath{x = 0123456789 888 111}
\end{document}
完整 MWE 输出
更新
鉴于数学字体及其特征在序言中是固定的,我猜您可以使用组合来\text
调整\addfontfeatures
运行文本中数字的外观以模拟数学风格。
版本
目前正在努力
XeTeX
版本 3.14159265-2.6-0.999992(MiKTeX 2.9.7440 64 位)mathspec
2016/12/22 v0.2bsiunitx
2020/05/25