2

I want to pass an information to a pgfkey that has to produce some code relatively to the node in which the key is set.

In this example I'd to access to the node (a) and put another node at (a.north east). (**) is the coordinates of the calling node (a) but I don't want to pass (a), the key has to guess by itself.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\newlength{\MboxL}
\tikzset{/.search also={/tikz},
    title/.code={\node[red] at (**) {#1};},
}

\begin{tikzpicture}

\node[draw,title=Nounours] (a) {The} ;

\end{tikzpicture}

\end{document}
Bernard
  • 271,350
Tarass
  • 16,912

1 Answers1

3

Something like in this answer? (Instead of code one has to use append after command and the \pgfextra, I think, since otherwise the current node is not "done".) I am wondering if section 17.4, in particular the node also trick, may be useful for you here.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
    title/.style = {
        append after command={
            \pgfextra{
                \node[red,anchor=south] at (\tikzlastnode.north east) (\tikzlastnode-outer) {#1};
            }
        }
    }
}

\begin{document}

\newlength{\MboxL}
\tikzset{/.search also={/tikz},
}

\begin{tikzpicture}

\node[draw,title=Nounours] (a) {The} ;

\node[draw] (b) at (5,0) {The} ;
\node also [label={[above,red,anchor=south west]:marmot}] (b);

\end{tikzpicture}

\end{document}

EDIT: Cleaned up a bit.