2

Is it possible, when defining a node, to give external (hierarchical) access to the subnode? Consider the following MWE, where I would like to give a stable access to the internal node, like something stable like (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}

"sub

2
  • 1
    Just a suggestion, but this feels like it might be more suited as a pic than a node. May 26 '19 at 9:21
  • Yes, I agree. The example was a simplified one for a case in circuitikz...
    – Rmano
    May 26 '19 at 13:34
4

The name of the current shape is stored in \tikz@fig@name.

\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}

enter image description here

1
  • Marmots really live in TikZ-low-level code burrows... Thanks a lot!
    – Rmano
    May 25 '19 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.