TikZ 图表中的 STIX 箭头提示

TikZ 图表中的 STIX 箭头提示

有没有一种令人满意的方法可以在 TikZ 图表中使用当前字体的箭头?我正在使用LuaLatexfontspecunicode-math来选择STIX Two字体,箭头看起来与 TikZ 图表中使用的箭头非常不同。

谷歌搜索让我相信目前还没有“支持”的方式来做到这一点,但也许有人在这里有办法大部分有效

答案1

对于您的预期应用来说,这个答案可能有点晚了,但我碰巧在 TikZ 中重新创建了 STIX Two Math 箭头。如果您仍然需要它,您可以随意使用它。

我没有盯着原始箭头的屏幕截图并猜测控制点的位置,而是在 FontForge 中打开 STIX2Math.otf 并查找它们的确切坐标。(实际上我的意思是,我将这些箭头导出到 .eps 文件并使用它们。)因此它们应该与原始箭头几乎完全匹配。

我认为没有什么可解释的,所以我只粘贴下面的代码:

\documentclass{article}

%% Font setup:
\usepackage{ifluatex,ifxetex}
\ifluatex  %% lualatex
  \usepackage{fontspec,unicode-math}
  \setmainfont{STIX Two Text}
  \setmathfont{STIX Two Math}
\else
  \ifxetex %% xelatex
  \usepackage{fontspec,unicode-math}
    \setmainfont{STIX2Text-Regular.otf}[
      BoldFont       = STIX2Text-Bold.otf,
      ItalicFont     = STIX2Text-Italic.otf,
      BoldItalicFont = STIX2Text-BoldItalic.otf  ]
    \setmathfont{STIX2Math.otf}
  \else    %% (pdf)latex, presumably
    \usepackage{stix2}
  \fi
\fi

\usepackage{tikz}

%% Arrow declaration:
\makeatletter
\pgfdeclarearrow{
  name = stix,
  parameters = {\ifpgfarrowharpoon h\fi},
  setup code = {
    \ifpgfarrowharpoon
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{247\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-81\pgfutil@tempdima}
      \pgfarrowshullpoint{-81\pgfutil@tempdima}{224\pgfutil@tempdima}
      \pgfarrowshullpoint{-58\pgfutil@tempdima}{247\pgfutil@tempdima}
      \pgfarrowshullpoint{247\pgfutil@tempdima}{-34\pgfutil@tempdima}
      \pgfarrowshullpoint{0pt}{-34\pgfutil@tempdima}
    \else\ifpgfarrowreversed
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{0pt}
      \pgfarrowssetlineend{-\pgfutil@tempdima}
      \pgfarrowssetbackend{-208\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-208\pgfutil@tempdima}{181\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-188\pgfutil@tempdima}{201\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{0pt}{34\pgfutil@tempdima}
    \else\ifdim\pgfinnerlinewidth>\z@
      \pgfutil@tempdima=\dimexpr\pgflinewidth/272
      \pgfarrowssettipend{324\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-73\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-73\pgfutil@tempdima}{285\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-51\pgfutil@tempdima}{305\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{324\pgfutil@tempdima}{5\pgfutil@tempdima}
    \else
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{192\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-72\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-72\pgfutil@tempdima}{181\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-51\pgfutil@tempdima}{201\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-192\pgfutil@tempdima}{5\pgfutil@tempdima}
    \fi\fi\fi
  },
  drawing code = {
    \ifpgfarrowharpoon %% harpoon
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{40}{34}}{\pgfpoint{44}{50}}{\pgfpoint{44}{66}}
      \pgfpathcurveto{\pgfpoint{44}{94}}{\pgfpoint{-22}{156}}{\pgfpoint{-81}{224}}
      \pgfpathlineto{\pgfpoint{-58}{247}}
      \pgfpathcurveto{\pgfpoint{44}{147}}{\pgfpoint{117}{66}}{\pgfpoint{247}{-30}}
      \pgfpathlineto{\pgfpoint{247}{-34}}
      \pgfpathlineto{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \else\ifpgfarrowreversed %% reversed arrowhead
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{-73}{78}}{\pgfpoint{-134}{138}}{\pgfpoint{-188}{201}}
      \pgfpathlineto{\pgfpoint{-208}{181}}
      \pgfpathcurveto{\pgfpoint{-185}{147}}{\pgfpoint{-152}{118}}{\pgfpoint{-124}{83}}
      \pgfpathcurveto{\pgfpoint{-111}{65}}{\pgfpoint{-95}{33}}{\pgfpoint{-95}{0}}
      \pgfpathcurveto{\pgfpoint{-95}{-33}}{\pgfpoint{-111}{-65}}{\pgfpoint{-124}{-83}}
      \pgfpathcurveto{\pgfpoint{-152}{-118}}{\pgfpoint{-185}{-147}}{\pgfpoint{-208}{-181}}
      \pgfpathlineto{\pgfpoint{-188}{-201}}
      \pgfpathcurveto{\pgfpoint{-134}{-138}}{\pgfpoint{-73}{-78}}{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \else\ifdim\pgfinnerlinewidth>\z@ %% double arrow
      \pgftransformscale{\pgflinewidth/272}
      \pgfpathmoveto{\pgfpoint{0}{136}}
      \pgfpathcurveto{\pgfpoint{18}{136}}{\pgfpoint{27}{151}}{\pgfpoint{27}{159}}
      \pgfpathcurveto{\pgfpoint{27}{175}}{\pgfpoint{20}{184}}{\pgfpoint{3}{202}}
      \pgfpathcurveto{\pgfpoint{-8}{213}}{\pgfpoint{-48}{256}}{\pgfpoint{-73}{285}}
      \pgfpathlineto{\pgfpoint{-51}{305}}
      \pgfpathcurveto{\pgfpoint{69}{187}}{\pgfpoint{198}{100}}{\pgfpoint{324}{5}}
      \pgfpathlineto{\pgfpoint{324}{-5}}
      \pgfpathcurveto{\pgfpoint{198}{-100}}{\pgfpoint{69}{-187}}{\pgfpoint{-51}{-305}}
      \pgfpathlineto{\pgfpoint{-73}{-285}}
      \pgfpathcurveto{\pgfpoint{-48}{-256}}{\pgfpoint{-8}{-213}}{\pgfpoint{3}{-202}}
      \pgfpathcurveto{\pgfpoint{20}{-184}}{\pgfpoint{27}{-175}}{\pgfpoint{27}{-159}}
      \pgfpathcurveto{\pgfpoint{27}{-151}}{\pgfpoint{18}{-136}}{\pgfpoint{0}{-136}}
      \pgftransformreset
      \pgfpathlineto{\pgfpoint{0}{-.5*\pgfinnerlinewidth}}
      \pgftransformxshift{208\pgflinewidth/272}
      \pgftransformscale{\pgfinnerlinewidth/136}
      \pgfpathlineto{\pgfpoint{-61}{-68}}
      \pgfpathcurveto{\pgfpoint{-27}{-49}}{\pgfpoint{0}{-24}}{\pgfpoint{0}{0}}
      \pgfpathcurveto{\pgfpoint{0}{24}}{\pgfpoint{-27}{49}}{\pgfpoint{-61}{68}}
      \pgftransformreset
      \pgfpathlineto{\pgfpoint{0}{.5*\pgfinnerlinewidth}}
      \pgfpathclose
      \pgfusepathqfill
    \else %% normal arrowhead
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{18}{34}}{\pgfpoint{26}{44}}{\pgfpoint{26}{54}}
      \pgfpathcurveto{\pgfpoint{26}{63}}{\pgfpoint{21}{74}}{\pgfpoint{12}{83}}
      \pgfpathcurveto{\pgfpoint{-19}{115}}{\pgfpoint{-48}{148}}{\pgfpoint{-72}{181}}
      \pgfpathlineto{\pgfpoint{-51}{201}}
      \pgfpathcurveto{\pgfpoint{16}{123}}{\pgfpoint{94}{47}}{\pgfpoint{192}{5}}
      \pgfpathlineto{\pgfpoint{192}{-5}}
      \pgfpathcurveto{\pgfpoint{94}{-47}}{\pgfpoint{16}{-123}}{\pgfpoint{-51}{-201}}
      \pgfpathlineto{\pgfpoint{-72}{-181}}
      \pgfpathcurveto{\pgfpoint{-48}{-148}}{\pgfpoint{-19}{-115}}{\pgfpoint{12}{-83}}
      \pgfpathcurveto{\pgfpoint{21}{-74}}{\pgfpoint{26}{-63}}{\pgfpoint{26}{-54}}
      \pgfpathcurveto{\pgfpoint{26}{-44}}{\pgfpoint{18}{-34}}{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \fi\fi\fi
  }
}
\pgfdeclarearrow{
  name = stixhooks,
  parameters = {\ifpgfarrowharpoon h\fi},
  setup code = {
    \pgfutil@tempdima=\dimexpr\pgflinewidth/68
    \pgfarrowssettipend{184\pgfutil@tempdima}
    \pgfarrowssetlineend{\pgfutil@tempdima}
    \pgfarrowssetbackend{-79\pgfutil@tempdima}
    \pgfarrowsupperhullpoint{-79\pgfutil@tempdima}{307\pgfutil@tempdima}
    \pgfarrowsupperhullpoint{184\pgfutil@tempdima}{136\pgfutil@tempdima}
    \ifpgfarrowharpoon\pgfarrowshullpoint{0pt}{-34\pgfutil@tempdima}\fi
  },
  drawing code = {
    \pgftransformscale{\pgflinewidth/68}
    \ifpgfarrowharpoon\else %% double-sidded
      \pgfpathmoveto{\pgfpoint{0}{-34}}
      \pgfpathcurveto{\pgfpoint{61}{-34}}{\pgfpoint{117}{-68}}{\pgfpoint{117}{-135}}
      \pgfpathcurveto{\pgfpoint{117}{-197}}{\pgfpoint{79}{-239}}{\pgfpoint{18}{-239}}
      \pgfpathlineto{\pgfpoint{-79}{-239}}
      \pgfpathlineto{\pgfpoint{-79}{-307}}
      \pgfpathlineto{\pgfpoint{21}{-307}}
      \pgfpathcurveto{\pgfpoint{99}{-307}}{\pgfpoint{184}{-245}}{\pgfpoint{184}{-136}}
      \pgfpathcurveto{\pgfpoint{184}{-20}}{\pgfpoint{80}{34}}{\pgfpoint{0}{34}}
      \pgfpathclose
      \pgfusepathqfill
    \fi
    \pgfpathmoveto{\pgfpoint{0}{34}}
    \pgfpathcurveto{\pgfpoint{61}{34}}{\pgfpoint{117}{68}}{\pgfpoint{117}{135}}
    \pgfpathcurveto{\pgfpoint{117}{197}}{\pgfpoint{79}{239}}{\pgfpoint{18}{239}}
    \pgfpathlineto{\pgfpoint{-79}{239}}
    \pgfpathlineto{\pgfpoint{-79}{307}}
    \pgfpathlineto{\pgfpoint{21}{307}}
    \pgfpathcurveto{\pgfpoint{99}{307}}{\pgfpoint{184}{245}}{\pgfpoint{184}{136}}
    \pgfpathcurveto{\pgfpoint{184}{20}}{\pgfpoint{84}{-34}}{\pgfpoint{4}{-34}}
    \pgfpathclose
    \pgfusepathqfill
  }
}
\makeatother

%% For the Bar arrowhead stlye
\usetikzlibrary{arrows.meta}

%% STIX arrows have a line width of exactly 0.68em:
\tikzset{every picture/.style={line width=.068em}}

%% Set up arrowheads:
\tikzset{>=stix,
         |/.tip={Bar[width=.403em,line width=.052em]},
         lefthook/.tip={stixhooks[left]},
         righthook/.tip={stixhooks[right]},
         leftharpoon/.tip={>[left]},
         rightharpoon/.tip={>[right]}
}

%% For testing purposes:
%% This prints $#2$ and a Tikz arrow with head #3 of length #1
%% Then it prints the latter overlayed on the former
\newcommand*\stixtest[3][.805em]{%
  $#2$
  &
  $\vcenter{\hbox{$\tikz{
    \useasboundingbox (0,0) -- (#1,0);
    \draw[#3] (0,0) -- (#1,0);
  }$}}$
  &
  \ooalign{\hfil$#2$\hfil\cr\hfil
      $\vcenter{\hbox{$\tikz[transparency group,opacity=.5]{
        \useasboundingbox (0,0) -- (#1,0);
        \draw[#3,red] (0,0) -- (#1,0);
      }$}}$\hfil}
}

\begin{document}

\renewcommand\arraystretch{0} %% <- reduce space between rows
\begin{tabular}{c@{}c@{}c}
\stixtest[.805em]{\rightarrow}{->}
\\ %% \hskip below is necessary because \Rightarrow has uneven spacing
\stixtest[.826em]{\hskip.041em\Rightarrow}{->,double distance=2\pgflinewidth}
\\
\stixtest[.867em]{\rightharpoonup}{-leftharpoon}
\\
\stixtest[.805em]{\mapsto}{|->}
\\
\stixtest[.805em]{\rightarrowtail}{>->}
\\
\stixtest[.805em]{\hookrightarrow}{righthook->}
\end{tabular}

\end{document}

我在下面插入的输出表格中,左侧显示了 STIX Two Math 字体的箭头,中间显示了相应的 TikZ 箭头。在最右边的列中,我将后者叠加在前者之上(红色,不透明度为 50%)。

箭!

几点说明

  • STIX Two Math 字体的箭头的线宽恰好为 0.068em(= 10pt 处的 0.68pt),这就是我添加线条的原因\tikzset{every picture/.style={line width=.068em}}。如果使用不同的线宽,所有箭头都会相应缩放。

  • 要正确显示双箭头[->,double distance=2\pgflinewidth],您应该使用 ,就像我上面所做的那样。其他距离也可以,但它们不会像字形\Rightarrow(双线末端的微小线条是由于 TikZ 通过在较粗的黑线上方绘制白线来绘制双线而导致的渲染伪影。它们不应该出现在打​​印中。)

  • 我必须制作一个单独的stixhooks箭头样式,因为 STIX Two字形的钩子与使用库中的箭头\hookrightarrow创建的任何钩子都不同。Hooksarrows.meta

  • 不要组合箭头样式:箭头可以是双重的、鱼叉状的或反转的,但这些样式目前无法组合。

  • 由于它相当长,您可能需要将此序言(部分)放在单独的 .tex 文件中\input(或放在 .sty 文件中,以便您可以\usepackage这样做)。

示范

为了演示,我修改了一个漂亮的图表的一些箭头,从而破坏了它。

\documentclass{article}

%% Font setup:
\usepackage{ifluatex,ifxetex}
\ifluatex  %% lualatex
  \usepackage{fontspec,unicode-math}
  \setmainfont{STIX Two Text}
  \setmathfont{STIX Two Math}
\else
  \ifxetex %% xelatex
  \usepackage{fontspec,unicode-math}
    \setmainfont{STIX2Text-Regular.otf}[
      BoldFont       = STIX2Text-Bold.otf,
      ItalicFont     = STIX2Text-Italic.otf,
      BoldItalicFont = STIX2Text-BoldItalic.otf  ]
    \setmathfont{STIX2Math.otf}
  \else    %% (pdf)latex, presumably
    \usepackage{stix2}
  \fi
\fi

\usepackage{tikz}

%% Arrow declaration:
\makeatletter
\pgfdeclarearrow{
  name = stix,
  parameters = {\ifpgfarrowharpoon h\fi},
  setup code = {
    \ifpgfarrowharpoon
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{247\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-81\pgfutil@tempdima}
      \pgfarrowshullpoint{-81\pgfutil@tempdima}{224\pgfutil@tempdima}
      \pgfarrowshullpoint{-58\pgfutil@tempdima}{247\pgfutil@tempdima}
      \pgfarrowshullpoint{247\pgfutil@tempdima}{-34\pgfutil@tempdima}
      \pgfarrowshullpoint{0pt}{-34\pgfutil@tempdima}
    \else\ifpgfarrowreversed
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{0pt}
      \pgfarrowssetlineend{-\pgfutil@tempdima}
      \pgfarrowssetbackend{-208\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-208\pgfutil@tempdima}{181\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-188\pgfutil@tempdima}{201\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{0pt}{34\pgfutil@tempdima}
    \else\ifdim\pgfinnerlinewidth>\z@
      \pgfutil@tempdima=\dimexpr\pgflinewidth/272
      \pgfarrowssettipend{324\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-73\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-73\pgfutil@tempdima}{285\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-51\pgfutil@tempdima}{305\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{324\pgfutil@tempdima}{5\pgfutil@tempdima}
    \else
      \pgfutil@tempdima=\dimexpr\pgflinewidth/68
      \pgfarrowssettipend{192\pgfutil@tempdima}
      \pgfarrowssetlineend{\pgfutil@tempdima}
      \pgfarrowssetbackend{-72\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-72\pgfutil@tempdima}{181\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-51\pgfutil@tempdima}{201\pgfutil@tempdima}
      \pgfarrowsupperhullpoint{-192\pgfutil@tempdima}{5\pgfutil@tempdima}
    \fi\fi\fi
  },
  drawing code = {
    \ifpgfarrowharpoon %% harpoon
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{40}{34}}{\pgfpoint{44}{50}}{\pgfpoint{44}{66}}
      \pgfpathcurveto{\pgfpoint{44}{94}}{\pgfpoint{-22}{156}}{\pgfpoint{-81}{224}}
      \pgfpathlineto{\pgfpoint{-58}{247}}
      \pgfpathcurveto{\pgfpoint{44}{147}}{\pgfpoint{117}{66}}{\pgfpoint{247}{-30}}
      \pgfpathlineto{\pgfpoint{247}{-34}}
      \pgfpathlineto{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \else\ifpgfarrowreversed %% reversed arrowhead
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{-73}{78}}{\pgfpoint{-134}{138}}{\pgfpoint{-188}{201}}
      \pgfpathlineto{\pgfpoint{-208}{181}}
      \pgfpathcurveto{\pgfpoint{-185}{147}}{\pgfpoint{-152}{118}}{\pgfpoint{-124}{83}}
      \pgfpathcurveto{\pgfpoint{-111}{65}}{\pgfpoint{-95}{33}}{\pgfpoint{-95}{0}}
      \pgfpathcurveto{\pgfpoint{-95}{-33}}{\pgfpoint{-111}{-65}}{\pgfpoint{-124}{-83}}
      \pgfpathcurveto{\pgfpoint{-152}{-118}}{\pgfpoint{-185}{-147}}{\pgfpoint{-208}{-181}}
      \pgfpathlineto{\pgfpoint{-188}{-201}}
      \pgfpathcurveto{\pgfpoint{-134}{-138}}{\pgfpoint{-73}{-78}}{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \else\ifdim\pgfinnerlinewidth>\z@ %% double arrow
      \pgftransformscale{\pgflinewidth/272}
      \pgfpathmoveto{\pgfpoint{0}{136}}
      \pgfpathcurveto{\pgfpoint{18}{136}}{\pgfpoint{27}{151}}{\pgfpoint{27}{159}}
      \pgfpathcurveto{\pgfpoint{27}{175}}{\pgfpoint{20}{184}}{\pgfpoint{3}{202}}
      \pgfpathcurveto{\pgfpoint{-8}{213}}{\pgfpoint{-48}{256}}{\pgfpoint{-73}{285}}
      \pgfpathlineto{\pgfpoint{-51}{305}}
      \pgfpathcurveto{\pgfpoint{69}{187}}{\pgfpoint{198}{100}}{\pgfpoint{324}{5}}
      \pgfpathlineto{\pgfpoint{324}{-5}}
      \pgfpathcurveto{\pgfpoint{198}{-100}}{\pgfpoint{69}{-187}}{\pgfpoint{-51}{-305}}
      \pgfpathlineto{\pgfpoint{-73}{-285}}
      \pgfpathcurveto{\pgfpoint{-48}{-256}}{\pgfpoint{-8}{-213}}{\pgfpoint{3}{-202}}
      \pgfpathcurveto{\pgfpoint{20}{-184}}{\pgfpoint{27}{-175}}{\pgfpoint{27}{-159}}
      \pgfpathcurveto{\pgfpoint{27}{-151}}{\pgfpoint{18}{-136}}{\pgfpoint{0}{-136}}
      \pgftransformreset
      \pgfpathlineto{\pgfpoint{0}{-.5*\pgfinnerlinewidth}}
      \pgftransformxshift{208\pgflinewidth/272}
      \pgftransformscale{\pgfinnerlinewidth/136}
      \pgfpathlineto{\pgfpoint{-61}{-68}}
      \pgfpathcurveto{\pgfpoint{-27}{-49}}{\pgfpoint{0}{-24}}{\pgfpoint{0}{0}}
      \pgfpathcurveto{\pgfpoint{0}{24}}{\pgfpoint{-27}{49}}{\pgfpoint{-61}{68}}
      \pgftransformreset
      \pgfpathlineto{\pgfpoint{0}{.5*\pgfinnerlinewidth}}
      \pgfpathclose
      \pgfusepathqfill
    \else %% normal arrowhead
      \pgftransformscale{\pgflinewidth/68}
      \pgfpathmoveto{\pgfpoint{0}{34}}
      \pgfpathcurveto{\pgfpoint{18}{34}}{\pgfpoint{26}{44}}{\pgfpoint{26}{54}}
      \pgfpathcurveto{\pgfpoint{26}{63}}{\pgfpoint{21}{74}}{\pgfpoint{12}{83}}
      \pgfpathcurveto{\pgfpoint{-19}{115}}{\pgfpoint{-48}{148}}{\pgfpoint{-72}{181}}
      \pgfpathlineto{\pgfpoint{-51}{201}}
      \pgfpathcurveto{\pgfpoint{16}{123}}{\pgfpoint{94}{47}}{\pgfpoint{192}{5}}
      \pgfpathlineto{\pgfpoint{192}{-5}}
      \pgfpathcurveto{\pgfpoint{94}{-47}}{\pgfpoint{16}{-123}}{\pgfpoint{-51}{-201}}
      \pgfpathlineto{\pgfpoint{-72}{-181}}
      \pgfpathcurveto{\pgfpoint{-48}{-148}}{\pgfpoint{-19}{-115}}{\pgfpoint{12}{-83}}
      \pgfpathcurveto{\pgfpoint{21}{-74}}{\pgfpoint{26}{-63}}{\pgfpoint{26}{-54}}
      \pgfpathcurveto{\pgfpoint{26}{-44}}{\pgfpoint{18}{-34}}{\pgfpoint{0}{-34}}
      \pgfpathclose
      \pgfusepathqfill
    \fi\fi\fi
  }
}
\pgfdeclarearrow{
  name = stixhooks,
  parameters = {\ifpgfarrowharpoon h\fi},
  setup code = {
    \pgfutil@tempdima=\dimexpr\pgflinewidth/68
    \pgfarrowssettipend{184\pgfutil@tempdima}
    \pgfarrowssetlineend{\pgfutil@tempdima}
    \pgfarrowssetbackend{-79\pgfutil@tempdima}
    \pgfarrowsupperhullpoint{-79\pgfutil@tempdima}{307\pgfutil@tempdima}
    \pgfarrowsupperhullpoint{184\pgfutil@tempdima}{136\pgfutil@tempdima}
    \ifpgfarrowharpoon\pgfarrowshullpoint{0pt}{-34\pgfutil@tempdima}\fi
  },
  drawing code = {
    \pgftransformscale{\pgflinewidth/68}
    \ifpgfarrowharpoon\else %% double-sidded
      \pgfpathmoveto{\pgfpoint{0}{-34}}
      \pgfpathcurveto{\pgfpoint{61}{-34}}{\pgfpoint{117}{-68}}{\pgfpoint{117}{-135}}
      \pgfpathcurveto{\pgfpoint{117}{-197}}{\pgfpoint{79}{-239}}{\pgfpoint{18}{-239}}
      \pgfpathlineto{\pgfpoint{-79}{-239}}
      \pgfpathlineto{\pgfpoint{-79}{-307}}
      \pgfpathlineto{\pgfpoint{21}{-307}}
      \pgfpathcurveto{\pgfpoint{99}{-307}}{\pgfpoint{184}{-245}}{\pgfpoint{184}{-136}}
      \pgfpathcurveto{\pgfpoint{184}{-20}}{\pgfpoint{80}{34}}{\pgfpoint{0}{34}}
      \pgfpathclose
      \pgfusepathqfill
    \fi
    \pgfpathmoveto{\pgfpoint{0}{34}}
    \pgfpathcurveto{\pgfpoint{61}{34}}{\pgfpoint{117}{68}}{\pgfpoint{117}{135}}
    \pgfpathcurveto{\pgfpoint{117}{197}}{\pgfpoint{79}{239}}{\pgfpoint{18}{239}}
    \pgfpathlineto{\pgfpoint{-79}{239}}
    \pgfpathlineto{\pgfpoint{-79}{307}}
    \pgfpathlineto{\pgfpoint{21}{307}}
    \pgfpathcurveto{\pgfpoint{99}{307}}{\pgfpoint{184}{245}}{\pgfpoint{184}{136}}
    \pgfpathcurveto{\pgfpoint{184}{20}}{\pgfpoint{84}{-34}}{\pgfpoint{4}{-34}}
    \pgfpathclose
    \pgfusepathqfill
  }
}
\makeatother

%% For the Bar arrowhead stlye
\usetikzlibrary{arrows.meta}

%% STIX arrows have a line width of exactly 0.68em:
\tikzset{every picture/.style={line width=.068em}}

%% Set up arrowheads:
\tikzset{>=stix,
         |/.tip={Bar[width=.403em,line width=.052em]},
         lefthook/.tip={stixhooks[left]},
         righthook/.tip={stixhooks[right]},
         leftharpoon/.tip={>[left]},
         rightharpoon/.tip={>[right]}
}

%% For the diagram below:
\usetikzlibrary{matrix,positioning,}

\begin{document}

\[\begin{tikzpicture}
    \matrix (m) [matrix of math nodes,text height=1.4ex,text depth=0.15ex,column sep=2.5em,row sep=2.5em] {
      |(B)| B & |(C)| C \\
      |(D)| D & |(E)| E \\ };
    \node[above left=2.5em of B] (A) {$A$};
    \draw[->,dashed] (A) -- node[auto,inner sep=.2ex]{$\scriptstyle\exists!$} (B);
    \draw[righthook->>] (B) -- (C);
    \draw[->,double distance=2\pgflinewidth] (B) to (D);
    \draw[|->] (C) -- (E);
    \draw[>-leftharpoon] (D) -- (E);
    \draw[->,double distance=2\pgflinewidth] (A) to[out=0] (C);
    \draw[<->] (A) to[out=-90] (D);
\end{tikzpicture}\]

\end{document}

这个图以前很好


它们实际上并不匹配确切地因为 stix2 箭头并不完全对称(而我的箭头是对称的)。STIX Two 箭头上半部分有相当多的(控制)点与下半部分的箭头相差 0.001em(由于舍入误差?),并且有几个相差更多(由于粗心?)。它们可能不完全匹配的另一个原因是字体的渲染方式可能与使用 TikZ 绘制的任何字体略有不同。

答案2

使用arrow style=math font(手册第 2.2 节tikz-cd):

\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{tikz-cd}

\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\tikzcdset{arrow style=math font}

\begin{document}

\[
a\to b \qquad
\begin{tikzcd}
a \arrow[r] \arrow[dr] & b \arrow[d] \\
& c
\end{tikzcd}
\]

\end{document}

在此处输入图片描述

相关内容