PGF 手册中的自定义箭头尖示例

PGF 手册中的自定义箭头尖示例

从 PGF 手册第 1025 页粘贴的以下代码在我这边无法编译。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\pgfdeclarearrow{
name = foo,
parameters = { \the\pgfarrowlength },
setup code = {
% The different end values:
\pgfarrowssettipend{.25\pgfarrowlength}
\pgfarrowssetlineend{-.25\pgfarrowlength}
\pgfarrowssetvisualbackend{-.5\pgfarrowlength}
\pgfarrowssetbackend{-.75\pgfarrowlength}
% The hull
\pgfarrowshullpoint{.25\pgfarrowlength}{0pt}
\pgfarrowshullpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}
\pgfarrowshullpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}
% Saves: Only the length:
\pgfarrowssavethe\pgfarrowlength
},
drawing code = {
\pgfpathmoveto{.25\pgfarrowlength}{0pt}
\pgfpathlineto{-.75\pgfarrowlength}{.5\pgfarrowlength}
\pgfpathlineto{-.5\pgfarrowlength}{0pt}
\pgfpathlineto{-.75\pgfarrowlength}{-.5\pgfarrowlength}
\pgfpathclose
\pgfusepathqfill
},
defaults = { length = 4cm }
}


\begin{document}

\tikz \draw [-foo] (0,0) -- (8,0);

\end{document}

怎么了?

答案1

绘制代码实际上是这样的:

\pgfpathmoveto{\pgfqpoint{.25\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}}
\pgfpathlineto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}}
\pgfpathclose
\pgfusepathqfill

如果您将它替换为您已有的那个,它就会起作用。

我检查了手册源。使用的代码与 PDF 中看到的不同。不知道为什么。

相关内容