How could I show tikz node names in the output (e.g. in a label)

Do you want something like this?

Courtesy of Alenanno ...

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
    mystyle/.style={%
      label={right:\pgfkeysvalueof{/pgf/minimum width}},
    },
   my style/.style={%
     append after command={% courtesy of Alenanno ref: https://tex.stackexchange.com/questions/287967/drawing-thin-line-around-a-multipart-tikz-shape#comment696552_287972
       \pgfextra{\node [right] at (\tikzlastnode.mid east) {\tikzlastnode};}
     },
   },
  ]
  \node (n1) [mystyle, draw] {1};
  \node (n2) [my style, draw] at (0,1) {2};
\end{tikzpicture}
\end{document}

name to right

EDIT

Following up on percusse's comment, you can see that

  \draw (0,0) -- (1,1) node (n2) [my style, draw] {2} -- (2,2) node (n3) [my style, draw]{2};

does what is wanted in terms of locating the nodes ...

what I would expect location-wise, but not otherwise

but not what you might hope otherwise ....


That needs a rather deep hack that you might not want to get involved with. Mainly because the names are not set as a value but they are roughly speaking pointers to shape ids.

Instead you can use your own style such that you can skip parentheses and set the name and the label at the same time. And when you are done you basically remove the label part.

\begin{tikzpicture}[mystyle/.style={name = #1, label={right:#1}}]
  \node [mystyle=n1, draw] {1};
\end{tikzpicture} 

Tags:

Tikz Pgf