我之前帖子的后续问题这里在我的文档中,我想用与正文不同的字体排版表格。我设法使它适用于常规输入。但是,我偶尔需要在表格中使用数学。此时,字体会切换回正文的常规字体。我尝试使用该mathspec
软件包,但无法使其工作。我如何暂时更改表格的数学字体?
请参阅下面的示例。我并不严格遵守fontspec
//解决方案,但由于我的其余设置很大程度上依赖于它,因此我宁愿不必对其进行太多更改,也不要添加更多其他软件包mathspec
。xetex
\documentclass{scrartcl}
\usepackage{mathspec}
\usepackage{tabularx}
\setmainfont[Ligatures=TeX, Numbers={OldStyle, Proportional}]{TeX Gyre Pagella}
\setsansfont[Ligatures=TeX, Numbers={Lining, Proportional}]{TeX Gyre Heros}
\setmathfont(Digits,Latin,Greek)[Numbers={Lining, Proportional}]{TeX Gyre Pagella}
\setmathsf[Numbers={Lining, Monospaced}]{TeX Gyre Heros}
\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{%
\sffamily\addfontfeature{Numbers={Monospaced, Lining}}%
}
\begin{document}
\section{A test}
This is a font test.
test, 1, 2, 3, 5, 7, 9, $1, 2, 3, 5, 7, 9,\mathsf{9}$.
\begin{table}
\begin{tabularx}{.25\linewidth}{lcc}
& Test & $a=b$ \\
a & 1, 5 & $\mathsf{9}$ \\
b & 2, 7 & $5$ \\
c & 3, 9 & $3$ \\
\end{tabularx}
\end{table}
\end{document}
(我看见这次讨论,这与我的问题相关但并未完全解决我的问题。)
答案1
感谢@DavidCarlisle 向我介绍了这一讨论这里,并给出示例这里,我已成功解决了我的问题。请参见下文。
\documentclass{scrartcl}
\usepackage{unicode-math}
\usepackage{fontspec}
\usepackage{tabularx}
\DeclareMathVersion{table}
\setmainfont[Ligatures=TeX, Numbers={OldStyle, Proportional}]{TeX Gyre Pagella}
\setsansfont[Ligatures=TeX, Numbers={Lining, Proportional}]{TeX Gyre Heros}
\setmathfont[math-style=TeX, version=normal]{TeX Gyre Pagella}
\setmathfont[math-style=upright, bold-style=upright, version=table]{TeX Gyre Heros}
\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{%
\sffamily\addfontfeature{Numbers={Monospaced, Lining}}%
\mathversion{table}
}
\begin{document}
\section{A test with formulas: $\mathbfup{a+b=c}$}
This is a font test.
\section{A test with formulas: $a+b=c$}
test, 1, 2, 3, 5, 7, 9, $5+4=9$, $a+b=c$.
\begin{table}
\begin{tabularx}{.25\linewidth}{lcc}
& Test & $a=b$ \\
a & 1, 5 & $9$ \\
b & 2, 7 & $5$ \\
c & 3, 9 & $3$ \\
\end{tabularx}
\end{table}
\end{document}