定义节点时,是否可以为子节点提供外部(分层)访问权限?考虑以下 MWE,我想为内部节点提供稳定的访问权限,就像稳定的东西一样(A.innerC.180)
...
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{myshape}{
\savedanchor{\northeast}{%
\pgfpoint{1cm}{1cm}
}
\anchor{north}{\northeast\pgf@x=0cm\relax}
\anchor{east}{\northeast\pgf@y=0cm\relax}
\anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
\anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
\anchor{center}{
\pgfpointorigin
}
\behindbackgroundpath{
\pgfnode{circle}{center}{}{innerC}{\pgfusepath{fill,stroke}}
\pgfpathmoveto{\pgfpointanchor{innerC}{-45}}
\pgfpathlineto{\pgfpoint{1cm}{-1cm}}
\pgfusepath{draw}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[myshape](A){};
% I have access to innerC node here:
\draw (innerC.90) -- ++(0,1);
% Now I lose access to the "innerC" of A:
\draw (2,0) node[myshape](B){};
\draw (innerC.90) -- ++(0,1);
% what I would like to do
% \draw (A.innerC.90) -- (B.innerC.90);
\end{tikzpicture}
\end{document}
答案1
当前形状的名称存储在\tikz@fig@名称。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{myshape}{
\savedanchor{\northeast}{%
\pgfpoint{1cm}{1cm}
}
\anchor{north}{\northeast\pgf@x=0cm\relax}
\anchor{east}{\northeast\pgf@y=0cm\relax}
\anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
\anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
\anchor{center}{
\pgfpointorigin
}
\behindbackgroundpath{
\pgfnode{circle}{center}{}{\tikz@fig@name-innerC}{\pgfusepath{fill,stroke}}
\pgfpathmoveto{\pgfpointanchor{\tikz@fig@name-innerC}{-45}}
\pgfpathlineto{\pgfpoint{1cm}{-1cm}}
\pgfusepath{draw}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[myshape](A){};
% I have access to innerC node here:
\draw (A-innerC.90) -- ++(0,1);
% Now I lose access to the "innerC" of A:
\draw (2,0) node[myshape](B){};
\draw (B-innerC.90) -- ++(0,1);
% what I would like to do
\draw (A-innerC.90) -- (B-innerC.90);
\end{tikzpicture}
\end{document}