# Custom labelling of nodes in a graph

I have this complete subgraph:

\begin{tikzpicture}
{ subgraph K_n; };
\end{tikzpicture}


If I wish to somehow distinguish vertex number 3, I can consult this question

\begin{tikzpicture}
{ 1; 2; 3[fill=gray]; 4; 5; subgraph K_n; };
\end{tikzpicture}


Now, suppose that instead of highlighting it, I wish to change it contents. For example, suppose I wish to change its label to the greek letter alpha, instead of the current 3. Something like this will not work:

\begin{tikzpicture}
{ 1; 2; 3[contents=$\alpha$]; 4; 5; subgraph K_n; };
\end{tikzpicture}


Any other way to achieve this fairly simple task, or, in general, label the vertices of K_n in a custom way? Of course, I can manually draw K_5 and label the nodes, but tikz graphs.standard library is nice and I wish to use it in order to avoid manual calculations.

# Update

I have a found a way to label vertex 3 with a different number.

\begin{tikzpicture}
{ subgraph K_n [V={1,2,7,4,5}];};
\end{tikzpicture}


This also works if instead of 7 I write a or FOO (in the last case it makes the node a bit larger). I can even put there 7/2.

What I can't put there instead of 7 is 7,2 (even inside {...}) or \alpha or $\alpha$ or {$\alpha$}. Trying any of these simply destroy the graph.

• Please complete your code so we can copy-paste-compile it rather than having to guess the packages and libraries you are using.
– cfr
Commented Nov 8, 2015 at 1:22

Not sure if this helps or not. It does not use the subgraph K_n but instead specifies the nodes manually so that their contents can be specified as desired. clique is used to draw the connections automatically, partially emulating the functionality provided by the subgraph.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\graph[nodes={draw, circle}, clique, n=5, clockwise, radius=2cm]
{
1/"$\alpha$", 2/"7,2", 3/"$x^2$", 4/"9,8,4", 5/"$\zeta$"
};
\end{tikzpicture}
\end{document}


thanks a lot. it's real helpful suggestion. I found it also works by simple node chains in a graph. So I guess it works in whole graph library.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {graphs}
\begin{document}

\tikz
\graph [
1/.style={ minimum size=10pt, draw, circle},
0/.style={empty nodes},
]
{
""      -!-06[0]-!-07[0]-!-08[0];
""      -!-16/"1"[1]->17/"2"[1]->18/"3"[1]->"y(n+3)";
"u(n+3)"-!-25/"1"[1]->26/"2"[1]->27/"3"[1]->"y(n+2)";
"u(n+2)"-!-34/"1"[1]->35/"2"[1]->36/"3"[1]->"y(n+1)";
"u(n+1)"-!-43/"1"[1]->44/"2"[1]->45/"3"[1]->"y(n)";
"u(n)"  -!-52/"1"[1]->53/"2"[1]->54/"3"[1]->"y(n-1)";
"u(n-1)"-!-61/"1"[1]->62/"2"[1]->63/"3"[1]->"y(n-2)";

"u(n-2)"-!-b0-!-b1-!-b2;
b0->[dotted]62->54;
b1->[dotted]63;
"u(n-2)"->[dotted]61->53->45;"u(n-1)"->52->44->36;"u(n)"->43->35->27;"u(n+1)"->34->26->18;"u(n+2)"->25->17;

b0          ->61->52->43->34->25->16->[dotted]06;
b1          ->62->53->44->35->26->17->[dotted]07;
b2          ->63->54->45->36->27->18->[dotted]08;
};
\end{document}