无论选择哪种数学字体, 该命令\tikzcdset{arrow style=math font}
似乎都会破坏包中箭头的渲染:tikz-cd
\documentclass{article}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\tikzcdset{arrow style=math font}
\begin{document}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\setmathfont{Libertinus Math}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\setmathfont{Latin Modern Math}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\setmathfont{STIX Two Math}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\end{document}
关于这个还能做什么?
如果无法解决,我还对使箭头与tikz-cd
数学字体相匹配的其他方法感兴趣。
答案1
tikz-cd
绘制箭头时假设两件事:
- 箭头的线宽与分数线的宽度相同,并且
- 箭头沿着数学轴延伸。
这两种情况对于每种数学字体来说都不成立。恕我直言,从 luatex 内部获取正确值是不可能的。您必须使用例如 font forge 查看字形定义。以下内容并不完美,但显示了如何调整值:
\documentclass{article}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\tikzcdset{arrow style=math font}
\begin{document}
\setmathfont{Libertinus Math}
$\frac{1}{b}\rightarrow xxx$
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\tikzcdset{every arrow/.append style={line width=0.52pt}}%smaller
\pgfmathdeclarefunction*{axis_height}{0}{%
\begingroup%
\pgfmathreturn2.65pt % smaller than the original
\endgroup}%
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\end{document}
答案2
根据 Ulrike Fischer 的回答,我编写了一个小包,其中存储了一些常用字体的值,即:,,,,,Libertinus Math
。我想在这里分享它们,以防有人遇到同样的问题。如果我添加TeX Gyre Pagella Math
更多字体,也许我也会更新答案。TeX Gyre Schola Math
TeX Gyre Bonum Math
STIX Two Math
Cambria Math
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mycd}
\RequirePackage{tikz-cd}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{tikz-cd}}
\newcommand{\tikzcdarrowdimens}[2]{%
\tikzcdset{every arrow/.append style={line width=#1}}%
\pgfmathdeclarefunction*{axis_height}{0}{%
\begingroup%
\pgfmathreturn#2%
\endgroup%
}%
}
\DeclareOption{Libertinus}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.052em}{0.250em}%
}
\DeclareOption{Pagella}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.060em}{0.250em}%
}
\DeclareOption{Schola}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.070em}{0.260em}%
}
\DeclareOption{Bonum}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.072em}{0.260em}%
}
\DeclareOption{STIX}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.068em}{0.259em}%
}
\DeclareOption{Cambria}{%
\tikzcdset{arrow style=math font}%
\tikzcdarrowdimens{0.06494140625em}{0.285888671875em}%
}
\ProcessOptions\relax
基本用法如下:
\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Libertinus Math}
\usepackage[Libertinus]{mycd}
\begin{document}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\end{document}