The list of names you specify for the key V
is used for the names of the nodes. These kind of names don't allow “special” macros like \mathbf
. (Node names are used as macro names internally by PGF and these need to be fully expandable to text. \mathbf
is not and all hell breaks loose because of that.)
However, the graphs
library provides the typeset
key where you have access to certain macros, mainly the \tikzgraphnodename
and the \tikzgraphnodetext
macros (which are the same in this simple case):
\graph[
clockwise,
n=3,
V={i,j,k},
edge={bend left=45, -stealth},
typeset=$\mathbf{\tikzgraphnodetext}$ % !or $\mathbf{\tikzgraphnodename}$
] { subgraph C_n };
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\tikz\graph[clockwise, n=3, V={i,j,k}, edge={bend left=45, -stealth}, % no typeset
] { subgraph C_n };
\tikz\graph[clockwise, n=3, V={i,j,k}, edge={bend left=45, -stealth}, % typeset with text
typeset=$\mathbf{\tikzgraphnodetext}$] { subgraph C_n };
\tikz\graph[clockwise, n=3, V={i,j,k}, edge={bend left=45, -stealth}, % typeset with name
typeset=$\mathbf{\tikzgraphnodename}$] { subgraph C_n };
\tikz\graph[clockwise, n=3, edge={bend left=45, -stealth}, % for fun
typeset=$v_{\tikzgraphnodetext}$,
nodes={text=red!\the\numexpr\tikzgraphnodetext00/3\relax!blue}
] { subgraph C_n };
\end{document}
Thanks to the comment of Henri Menke, a small fix to the subgraph I_n
(which is used internally by subgraph C_n
) enables you to use the full power of the \graph
way of specifying a vertex.
However, as it uses a \foreach
loop you need to protect ,
when they're used the node text or in the options (or in the node name but that's not a good idea to begin with).
V={ i / $\mathbf{i}$, j / $\mathbf{j}$, k / $\mathbf{k}$ [{red, fill=green}]}
or
V={ i / $\mathbf{i}$, j / $\mathbf{j}$, {k / $\mathbf{k}$ [red, fill=green]}}
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\makeatletter
\tikzgraphsset{
declare={subgraph I_n}{
\foreach \tikz@lib@graph@node@num in \tikzgraphV
{[parse/.expand once=\tikz@lib@graph@node@num]}}}
\makeatother
\begin{document}
\tikz\graph[clockwise, n=3,
V={ i / $\mathbf{i}$, j / $\mathbf{j}$, k / $\mathbf{k}$ },
edge={bend left=45, -stealth}] { subgraph C_n };
\end{document}
When I try to do so
means.\graph[clockwise, n=3, V={i,j,k}, typeset=$\mathbf{\tikzgraphnodename}$, edge={bend left=45, -stealth}] { subgraph C_n };
what you want? WithV
you specify the name of the nodes. These can't have names that include\mathbf
.