使用 xelatex 设置 tikz-cd 字形箭头尖的颜色

使用 xelatex 设置 tikz-cd 字形箭头尖的颜色

我正在使用Glyph来自的提示tikz-cd来获取像\looparrowright和朋友一样的箭头。

不过我想改变颜色。latex正确编译以下 MWE,但xelatex将循环留黑,同时将箭头的其余部分涂成红色。

\documentclass{standalone}
\usepackage{amsmath,amssymb}
\usepackage{tikz-cd}
\tikzset{
  loop/.tip={Glyph[glyph math command=looparrowleft, swap]},
  loop'/.tip={Glyph[glyph math command=looparrowleft]}
}

\begin{document}
  \begin{tikzcd}
    A \ar[r, loop->, red] & B \\
    % This arrow is red, but the loop part of the tip is black.
  \end{tikzcd}
\end{document}

答案1

这似乎与同样的旧 XeLaTeX 问题说到颜色,PGF/TikZ 就有。

作为修复\pgftext或以某种方式偷偷将另一个颜色\color命令放入其中的替代方法,这里有一个箭头Loop,可以绘制类似的东西。这只使用圆弧(半径为)在具有直径(± 线宽模糊度)inset的循环中。您使用的字形似乎使用了贝塞尔曲线,而不是具有固定半径的圆弧。如果这是预期的,则需要进行一些调整并摆弄良好的控制值。length\looparrowleft

您可以填充循环部分,您可以swap这样做,而且reversed在我看来,结果相当不错。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{cd}
\pgfdeclarearrow{
  name = Loop,
  parameters = {\the\pgfarrowlength,\the\pgfarrowinset,\ifpgfarrowopen o\fi},
  setup code =
    \ifdim\pgfarrowlength<\dimexpr2\pgfarrowinset+\pgflinewidth\relax
      \pgfarrowlength\dimexpr2\pgfarrowinset+\pgflinewidth\relax
    \fi
    \pgfarrowssettipend{\pgfarrowlength}%
    \pgfarrowssetlineend{.5\pgflinewidth}%
    \pgfarrowssavethe\pgfarrowlength
    \pgfarrowssavethe\pgfarrowinset,
  defaults = {length = +3pt +.3 +0, inset = +.75pt +1 +0},
  drawing code={%
    \pgfsetroundcap
    \pgfpathmoveto{\pgfqpoint{.5\pgflinewidth}{0pt}}%
    \pgfpathlineto{\pgfqpoint{\dimexpr\pgfarrowlength-.5\pgflinewidth-\pgfarrowinset}
                             {0pt}}%
    \pgfpatharc{+-90}{+0}{+\pgfarrowinset}%
    \pgfpathlineto{\pgfqpoint{\dimexpr\pgfarrowlength-.5\pgflinewidth}
                             {\dimexpr\pgfarrowlength-.5\pgflinewidth-\pgfarrowinset}}%
    \pgfpatharc{+0}{+90}{+\pgfarrowinset}%
    \pgfpathlineto{\pgfqpoint{\dimexpr\pgfarrowinset+.5\pgflinewidth}
                             {\dimexpr\pgfarrowlength-.5\pgflinewidth}}%
    \pgfpatharc{+90}{+180}{+\pgfarrowinset}%
    \pgfpathlineto{\pgfqpoint{\dimexpr\pgfarrowinset+.5\pgflinewidth-\pgfarrowinset}
                             {\dimexpr-\pgfarrowlength+.5\pgflinewidth}}%
    \ifpgfarrowopen\pgfusepathqstroke\else\pgfusepathqfillstroke\fi}}
\tikzset{
  Math Loop/.tip  = { Glyph[glyph math command=looparrowleft] },
  Loop Left/.tip  = {Loop[open, swap]},
  Loop Right/.tip = {Loop[open]}}
\begin{document}
\begin{tikzcd}
  A \ar[r, {Loop Left - Loop Right[blue]}, red] & B \\
  C \ar[r, /tikz/arrows={Loop Right[fill=pgfstrokecolor!50!yellow]
                       - Loop Left[yellow!80!black, reversed]}, green] & D
\end{tikzcd}
\color{blue}a \begin{pgfpicture}\pgftext{a}\end{pgfpicture}
\end{document}

输出

在此处输入图片描述

相关内容