17

According to the documentation for version 3.0.0 of PGF/TikZ (Section 19 Specifying Graphs, page 258), the powerful graphs library:

[...] offers a powerful path command for specifying how the nodes in a graph are connected by edges and arcs: The graph path command, which becomes available when you load the graphs library.

A few lines below there are some examples of the use of the path; amongst those examples one finds:

\tikz
  \graph [nodes={draw, circle}, clockwise, radius=.5cm, empty nodes, n=5] {
    subgraph I_n [name=inner] --[complete bipartite]
    subgraph I_n [name=outer]
};

and

\tikz
\graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
subgraph C_n [name=outer]
};

which should produce the following images (taking directly from the documentation):

enter image description here

However, when I try the exact same code in a "real" document:

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

\begin{document}

 \tikz
  \graph [nodes={draw, circle}, clockwise, radius=.5cm, empty nodes, n=5] {
    subgraph I_n [name=inner] --[complete bipartite]
    subgraph I_n [name=outer]
};
\tikz
  \graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
    subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
    subgraph C_n [name=outer]
};


\end{document}

This is all I get (image zoomed at 400%):

enter image description here

Even more disppointing is the following example on page 276:

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

\begin{document}

\tikz \graph [simple] {
subgraph K_n [n=8, clockwise];
% Get rid of the following edges:
1 -!- 2;
3 -!- 4;
6 -!- 8;
% And make one edge red:
1 --[red] 3;
};

\end{document}

The documentation shows this as the result:

enter image description here

but I only get an error message:

! Missing $ inserted.
<inserted text> 
$
l.15 }
    ;
? 

Am I missing something? Is some other library required in order to get the expected graphs?

7
  • 6
    Did some digging in the code for the documentation to find this: your MWEs work if the graphs and graphs.standard libraries are loaded (in that order). I don't see why this requirement would be intentional... maybe a bug? Mar 7, 2014 at 5:05
  • 1
    IMHO, the bug is with the subgraph keyword. It is not documented (alone)... and it offers no protection against errors: you may use any word after it without error (and without effect). Mar 7, 2014 at 7:05
  • @PaulGessler That's correct, would you like to turn this comment into an answer?
    – Stefan Kottwitz
    Mar 10, 2014 at 8:42
  • @StefanKottwitz, I could, but I'm not entirely sure why both are required. The documentation only uses lists graphs as being needed, so I wasn't sure if this was expected/intended or not. Mar 10, 2014 at 12:31
  • 1
    @PaulGessler graphs.standard is required to use subgraph K_n or subgraph I_n. The documentation only lists graphs because subgraph ... is used only to built an arbitrary graph in these examples. Mar 10, 2014 at 17:14

1 Answer 1

21

Based on looking through the pgf documentation's LaTeX source and also this answer, I believe that the documentation should list that both the graphs and graphs.standard libraries are included to produce these graphics.

All your examples work if I use \usetikzlibrary{graphs,graphs.standard} instead of only \usetikzlibrary{graphs}. Here is one sample:

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard} % both are required, in this order

\begin{document}
\tikz \graph [simple] {
  subgraph K_n [n=8, clockwise];
  % Get rid of the following edges:
  1 -!- 2;
  3 -!- 4;
  6 -!- 8;
  % And make one edge red:
  1 --[red] 3;
};
\end{document}

Output

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .