# How to know what is the current name of the node in which the pgfkey is set

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}


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.

• Didn't know about the also trick, thank you. – Tarass Mar 28 '18 at 5:26
• Or just \node[draw, label={[above,red,anchor=south west]:marmot}] (b) {The}; – Ignasi Mar 28 '18 at 7:50