我怎样才能(希望在文档中全局地)更改 TikZ 箭头的形状(包括tikzcd
环境中的箭头),以便与 TeX Gyre Terms Math 字体(使用 XeLaTeX)中的箭头匹配?
样式Straight Barb
几乎匹配,但倒钩的末端不同:在 TeX Gyre Termes Math 中,倒钩的末端是水平的,而在 TikZStraight Barb
头中,杆的末端垂直于倒钩的主体。
\documentclass[12pt]{article}
\usepackage[left=2.5in,right=2.5in]{geometry}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,decorations.markings}
\tikzset{
>={Straight Barb[scale=0.8]},
commutative diagrams/arrow style=tikz
}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Termes}[Scale=1.0]
\defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\large
\begin{equation} % eq 1
A \longrightarrow B \rightarrow C
\end{equation}
%
\begin{equation} % eq 2
\begin{tikzcd}
A \arrow[r,thick] {$f$} & B
\end{tikzcd}
\end{equation}
\end{document}
答案1
这官方的解决方案是math font
选择 tikz-cd。
\documentclass{article}
\usepackage{unicode-math}
\setmathfont{texgyrepagella-math.otf}
\usepackage{tikz,tikz-cd}
\tikzcdset{arrow style={math font}}
\pgfmathdeclarefunction*{axis_height}{0}{\begingroup\pgfmathreturn.25em\endgroup}
\pgfmathdeclarefunction*{rule_thickness}{0}{\begingroup\pgfmathreturn.06em\endgroup}
% credit to https://tex.stackexchange.com/questions/420034/tikzcdsetarrow-style-math-font-breaks-the-rendering-of-arrows
\begin{document}
\large
\begin{equation} % eq 1
A \longrightarrow B \rightarrow C
\end{equation}
%
\begin{equation} % eq 2
\begin{tikzcd}
A \arrow[r] {$f$} & B
\end{tikzcd}
\end{equation}
\end{document}
答案2
尝试这个:
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,decorations.markings}
\makeatletter
% based on the definition of arrow tip "Straight Barb"
\pgfdeclarearrow{
name = TeX Gyre Termes Math,
defaults = {
%%% <<< begin of change
length = +3.5pt 2,
%%% <<< end of change
width' = +0pt 2,
line width = +0pt 1 1,
},
setup code = {
% Compute front miter length:
\pgfmathdivide@{\pgf@sys@tonumber\pgfarrowlength}{\pgf@sys@tonumber\pgfarrowwidth}%
\let\pgf@temp@quot\pgfmathresult%
\pgf@x\pgfmathresult pt%
\pgf@x\pgfmathresult\pgf@x%
\pgf@x4\pgf@x%
\advance\pgf@x by1pt%
\pgfmathsqrt@{\pgf@sys@tonumber\pgf@x}%
\pgf@xc\pgfmathresult\pgfarrowlinewidth% xc is front miter
\[email protected]\pgf@xc
\pgf@xa\pgf@temp@quot\pgfarrowlinewidth% xa is extra harpoon miter
% Set ends
\ifpgfarrowroundjoin
\pgfarrowssettipend{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth}
\else
\pgfarrowssettipend{\pgfarrowlength\advance\pgf@x by\pgf@xc\ifpgfarrowharpoon\advance\pgf@x by\pgf@xa\fi}
\fi
\pgfarrowssetvisualbackend{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth}
\pgfarrowssetbackend{-.5\pgfarrowlinewidth}
% harpoon miter correction
\ifpgfarrowreversed
\pgfarrowssetlineend{\pgfarrowlength\ifpgfarrowharpoon\advance\pgf@x by.5\pgfarrowlinewidth\fi}
\else
\pgfarrowssetlineend{\pgfarrowlength\advance\pgf@x by-.5\pgfarrowlinewidth}
\fi
% The hull:
\ifpgfarrowroundjoin
\pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth}{\ifpgfarrowharpoon-.5\pgfarrowlinewidth\else0pt\fi}%
\else%
\ifpgfarrowharpoon
\pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by\pgf@xc\advance\pgf@x by\pgf@xa}{-.5\pgfarrowlinewidth}%
\else
\pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by\pgf@xc\advance\pgf@x by\pgf@xa}{0pt}%
\fi%
\fi
\pgfarrowsupperhullpoint{.5\pgfarrowlinewidth}{.5\pgfarrowwidth\advance\pgf@y by.5\pgfarrowlinewidth}%
\pgfarrowsupperhullpoint{-.5\pgfarrowlinewidth}{.5\pgfarrowwidth\advance\pgf@y by.5\pgfarrowlinewidth}%
\ifpgfarrowharpoon
\pgfarrowshullpoint{-.5\pgfarrowlinewidth}{-.5\pgfarrowlinewidth}%
\fi
% The following are needed in the code:
\pgfarrowssavethe\pgfarrowlinewidth
\pgfarrowssavethe\pgfarrowlength
\pgfarrowssavethe\pgfarrowwidth
},
drawing code = {
\pgfsetdash{}{+0pt}
\ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
\ifpgfarrowroundcap\pgfsetroundcap\else\pgfsetbuttcap\fi
\ifdim\pgfarrowlinewidth=\pgflinewidth\else\pgfsetlinewidth{+\pgfarrowlinewidth}\fi
\pgfpathmoveto{\pgfqpoint{0pt}{.5\pgfarrowwidth}}
\pgfpathlineto{\pgfqpoint{\pgfarrowlength}{0pt}}
\ifpgfarrowharpoon
\pgfpathlineto{\pgfqpoint{\pgfarrowlength\advance\pgf@x by\ifpgfarrowreversed\else-\fi\pgfarrowlinewidth}{0pt}}
\else
\pgfpathlineto{\pgfqpoint{0pt}{-.5\pgfarrowwidth}}
\fi
\pgfusepathqstroke
%%% <<< begin of change
% draw two white lines
\begin{pgfscope}
% \pgfsetstrokecolor{red}\pgfsetstrokeopacity{0.5} % just for test
\pgfsetstrokecolor{white}
\pgfmathsincos{atan2(2*\pgfarrowlength,\pgfarrowwidth)}
\pgfmathreciprocal{\pgfmathresulty}
\pgf@xa=\pgfmathresult\pgflinewidth
\pgf@ya=\pgfmathresultx pt
\pgf@ya=.5\pgf@ya
\pgf@ya=\dimexpr.5\pgfarrowwidth-\pgf@sys@tonumber\pgf@ya\pgflinewidth+.5\pgflinewidth\relax
% let w = arrow width, l = arrow length, x = line width,
% and tan(.) = w/(2l)
% top line = (-sin(.) * x/2, w/2 + (1-cos(.)) * x/2) -- +(sin(.) * x/2, 0pt),
% where -x/2 < -sin(.) * x/2 < 0
\pgfpathmoveto{\pgfqpoint{-.5\pgfarrowlinewidth}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
\ifpgfarrowharpoon
\else
\pgfpathmoveto{\pgfqpoint{-.5\pgfarrowlinewidth}{-\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{-\pgf@ya}}
\fi
\pgfusepathqstroke
\end{pgfscope}
%%% <<< end of change
},
parameters = {
\the\pgfarrowlinewidth,%
\the\pgfarrowlength,%
\the\pgfarrowwidth,%
\ifpgfarrowharpoon h\fi%
\ifpgfarrowroundjoin j\fi%
\ifpgfarrowroundcap c\fi%
},
}
\makeatother
\tikzset{
>={TeX Gyre Termes Math[scale=.8]}
}
\tikzcdset{
arrow style=tikz,
every arrow/.append style={line width=1.2pt}
}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Termes}[Scale=1.0]
\defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\Huge
\begin{equation} % eq 1
A \longrightarrow B \rightarrow C
\end{equation}
%
\begin{equation} % eq 2
\begin{tikzcd}
A \arrow[r, "f"] & B
\end{tikzcd}
\end{equation}
\end{document}