# How can one name a TikZ \graph and position a \node below it?

I'd like to place a node below a \graph in a tikzpicture. But, for some reason, I can't access the \graph.

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,graphs}
\begin{document}
\begin{tikzpicture}
\graph [name=graph] {a -> b};
\node[below of=graph] {$t_1$};
\end{tikzpicture}
\end{document}


results in: Package pgf Error: No shape named graph is known. ^^I\node[below of=graph] {$t_1$};

\graph (name) {...}; leads to File ended while scanning use of \tikz@lib@graph@node@naked.

\graph {a -> b} node[below] {$t_1$}; works but the label $t_1$ appears below the node a. Can I shift it to the centre?

(I'd prefer to use the graphs library and not graphdrawing, since the latter requires LuaLaTeX)

• There is also (current bounding box) to position nodes relative to. – John Kormylo Feb 26 at 14:11
• @JohnKormylo of course! \node[below of=current bounding box] {$t_1$}; works perfectly. Would you like to turn that into an answer so I can accept it? – Felix Emanuel Feb 26 at 14:57
• Nah. Don't really need the points. AFAICT, there are no more superpowers to be gained. – John Kormylo Feb 26 at 16:33

You can use a local bounding box.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,graphs}
\begin{document}
\begin{tikzpicture}
\begin{scope}[local bounding box=graph]
\graph  {a -> b};
\end{scope}
\node[below=1ex of graph] {$t_1$};
\end{tikzpicture}
\end{document}


I don't know if you can consider the graph as a whole like a big node (edit: Schrödinger's cat's answer does exactly that), but you can certainly name individual nodes of the graph and reference them in the rest of the tikzpicture:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, graphs, positioning}

\begin{document}

\begin{tikzpicture}
\graph {a[name=a] -> b[name=b]};
\coordinate (m) at ($(a)!0.5!(b)$); % midpoint between a and b
\node[below=0.5cm of m] {$t_1$};
\end{tikzpicture}

\end{document}


Note the use of below=0.5cm of m instead of the syntax below of=..., which doesn't make use of the positioning TikZ library.

There are other possibilities to tell that some particular node of your graph should be anchored at some particular position of your tikzpicture: see anchor node=, anchor here and desired at= in section Anchoring a Graph of the TikZ & PGF manual, around page 425.

Other ways to do the same:

\graph {a[name=a] -> b[name=b]};
\path (a) -- (b) node[pos=0.5, below=0.5cm] {$t_1$};


and

\graph {a[name=a] -> b[name=b]};
\path (a) -- node[pos=0.5, below=0.5cm] {$t_1$} (b);


The TikZ calc library is not needed for these last two techniques.