我正在尝试声明一个自定义 pgf 形状。我遇到一个问题,我无法访问东、西、北、南锚点。这有效:
\pgfdeclareshape{mixer}{%
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{north}
\inheritanchor[from=circle]{south}
\inheritanchor[from=circle]{west}
\inheritanchor[from=circle]{east}
\backgroundpath{%
\pgf@x=\radius
\pgf@y=\radius
\centerpoint \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\pgfpathcircle{\pgfpoint{\pgf@xa}{\pgf@ya}}{\radius}
}
}
但是,当我尝试使用类似的东西时:
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
或者
\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
我收到未定义的命令。这是为什么?
答案1
你还有机会:这些锚点的定义隐藏在
\pgf@anchor@⟨shape name⟩@⟨anchor name⟩
因此\north
可以通过
\pgf@anchor@mixer@north
完整代码
\documentclass{article}
\usepackage{tikz}
\begin{document}
\makeatletter
\pgfdeclareshape{mixer}{%
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{north}
\inheritanchor[from=circle]{south}
\inheritanchor[from=circle]{west}
\inheritanchor[from=circle]{east}
\backgroundpath{%
\centerpoint
\pgfpathcircle{\pgfpoint{\pgf@x}{\pgf@y}}{\radius}
\pgfpathmoveto{\pgf@anchor@mixer@east}
\pgfpathlineto{\pgf@anchor@mixer@north}
\pgfpathmoveto{\pgf@anchor@mixer@south}
\pgfpathlineto{\pgf@anchor@mixer@west}
\pgfusepath{stroke}
}
}
\tikz\node[mixer]{0123456789};
\end{document}