I am wondering how to reference a Tikz node outside a Tikz Picture, as if referring to an image. This page lists the possible \ref{} objects not including nodes, but maybe there is a package that it ignores. Anyway, I was wondering how it is usually done. Example:

\node (a) at (0,0){example node};
Desired function: ~\ref{node: a}, or something like this

I am currently using a node's label to explicitly reference it, but it doesn't seem like the best method.

  • 2
    Welcome to TeX.SX! Could you elaborate what you expect the \ref should return? Feb 5, 2019 at 18:34
  • Hello and thank you! I expect behavior similar to a \ref{fig:example}, where a number is displayed based on the image label. In this case, I am wondering how to label a node and then reference it in this manner.
    – Lara
    Feb 5, 2019 at 19:03
  • Here is a way to remember the content of a node. (I am not sure what you mean by number, do you want to auto-number all nodes? If so, should the node number also be inserted in the node?)
    – user121799
    Feb 5, 2019 at 19:06
  • Yes, auto-numbering them for referencing. The way presented in the link is what I am doing as of now, I was wondering if there is a more ''elegant'' way to do so :)
    – Lara
    Feb 5, 2019 at 19:10

1 Answer 1


If I understand correctly, you may be looking for this.

  1. \customlabel from this post is used to create a new referencable label. There you can also find what you could do if you don't want to use hyperref. Whether or not there is a version that works both with and without hyperref, I do not know.
  2. A new style referencable node is created that steps the node counter and also shows it as label.

And this is how you may use it.

\makeatletter% from https://tex.stackexchange.com/a/160035/121799
   \protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }%
\tikzset{autonumbered node/.style={/utils/exec={\stepcounter{node}},
\node[autonumbered node] (a) at (0,0) {example node\nodelabel{node:a}};
\node[autonumbered node] (b) at (2,1) {another example node\nodelabel{node:b}};

Node~\ref{node:a} is a node and so is \ref{node:b}.
\node[autonumbered node] (c) at (0,0) {yet another example node\nodelabel{node:c}};

Node~\ref{node:a} is on page~\pageref{node:a} and node~\ref{node:c} is on

enter image description here

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.