summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex')
-rw-r--r--graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex377
1 files changed, 192 insertions, 185 deletions
diff --git a/graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex b/graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex
index 7e4560d0da..7c51ffe0e7 100644
--- a/graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex
+++ b/graphics/pgf/base/doc/text-en/pgfmanual-en-tikz-graphs.tex
@@ -26,11 +26,11 @@ In this section, by \emph{graph} we refer to a set of nodes together with some
edges (sometimes also called arcs, in case they are directed) such as the
following:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> {b, c} -> d };
\end{codeexample}
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph {
subgraph I_nm [V={a, b, c}, W={1,...,4}];
@@ -40,7 +40,7 @@ following:
};
\end{codeexample}
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz
\graph [nodes={draw, circle}, clockwise, radius=.5cm, empty nodes, n=5] {
subgraph I_n [name=inner] --[complete bipartite]
@@ -48,7 +48,10 @@ following:
};
\end{codeexample}
-\begin{codeexample}[]
+\begin{codeexample}[
+ preamble={\usetikzlibrary{graphs}},
+ pre={\definecolor{graphicbackground}{rgb}{0.96,0.96,0.8}},
+]
\tikz
\graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
@@ -56,7 +59,7 @@ following:
};
\end{codeexample}
-\begin{codeexample}[width=6.6cm]
+\begin{codeexample}[width=6.6cm,preamble={\usetikzlibrary{graphs}}]
\tikz [>={To[sep]}, rotate=90, xscale=-1,
mark/.style={fill=black!50}, mark/.default=]
\graph [trie, simple,
@@ -85,10 +88,10 @@ following:
\end{codeexample}
The nodes of a graph are normal \tikzname\ nodes, the edges are normal lines
-drawn between nodes. There is nothing in the |graph| library that you cannot do
-using the normal |\node| and the |edge| commands. Rather, its purpose is to
+drawn between nodes. There is nothing in the |graphs| library that you cannot
+do using the normal |\node| and the |edge| commands. Rather, its purpose is to
offer a concise and powerful way of \emph{specifying} which nodes are present
-and how they are connected. The |graph| library only offers simple methods for
+and how they are connected. The |graphs| library only offers simple methods for
specifying \emph{where} the nodes should be shown, its main strength is in
specifying which nodes and edges are present in principle. The problem of
finding ``good positions on the canvas'' for the nodes of a graph is left to
@@ -131,12 +134,12 @@ and then using Lua\TeX, resulting in the following drawing of the same graph:
\medskip
\fi
-The |graph| library uses a syntax that is quite different from the normal
+The |graphs| library uses a syntax that is quite different from the normal
\tikzname\ syntax for specifying nodes. The reason for this is that for many
medium-sized graphs it can become quite cumbersome to specify all the nodes
using |\node| repeatedly and then using a great number of |edge| command;
possibly with complicated |\foreach| statements. Instead, the syntax of the
-|graph| library is loosely inspired by the \textsc{dot} format, which is quite
+|graphs| library is loosely inspired by the \textsc{dot} format, which is quite
useful for specifying medium-sized graphs, with some extensions on top.
@@ -152,7 +155,7 @@ sections.
The basic way of specifying a graph is to write down a \emph{node chain} as in
the following example:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz [every node/.style = draw]
\graph { foo -> bar -> blub };
\end{codeexample}
@@ -165,7 +168,7 @@ the following.
Inside a graph there can be more than one chain:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> b -> c;
d -> e -> f;
@@ -182,7 +185,7 @@ When a node like |f| is created, both the node name and the node text are
identical by default. This is not always desirable and can be changed by using
the |as| key or by providing another text after a slash:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
x1/$x_1$ -> x2 [as=$x_2$, red] -> x34/{$x_3,x_4$};
x1 -> [bend left] x34;
@@ -193,7 +196,7 @@ When you wish to use a node name that contains special symbols like commas or
dashes, you must surround the node name by quotes. This allows you to use quite
arbitrary text as a ``node name'':
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
"$x_1$" -> "$x_2$"[red] -> "$x_3,x_4$";
"$x_1$" ->[bend left] "$x_3,x_4$";
@@ -210,7 +213,7 @@ get interesting when you write down a node or even a whole group and connect it
to another group. In this case, the ``exit points'' of the first node or group
get connected to the ``entry points'' of the second node or group:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> {
b -> c,
@@ -221,7 +224,7 @@ get connected to the ``entry points'' of the second node or group:
Chain groups make it easy to create tree structures:
%
-\begin{codeexample}[width=10cm]
+\begin{codeexample}[width=10cm,preamble={\usetikzlibrary{graphs}}]
\tikz
\graph [grow down,
branch right=2.5cm] {
@@ -269,7 +272,7 @@ When connectors like |->| or |--| are used to connect nodes or whole chain
groups, one or more edges will typically be created. These edges can be styles
easily by providing options in square brackets directly after these connectors:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a ->[red] b --[thick] {c, d};
};
@@ -278,7 +281,7 @@ easily by providing options in square brackets directly after these connectors:
Using the quotes syntax, see Section~\ref{section-label-quotes}, you can even
add labels to the edges easily by putting the labels in quotes:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph {
a ->[red, "foo"] b --[thick, "bar"] {c, d};
};
@@ -295,7 +298,7 @@ somehow also indicate that these options actually ``belong'' to the edge
``leading to'' to nodes. This is achieved by preceding the options with a
greater-than sign:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph {
a -> b -- {c [> "foo"], d [> "bar"']};
};
@@ -304,7 +307,7 @@ greater-than sign:
Symmetrically, preceding the options by |<| causes the options and labels to
apply to the ``outgoing'' edges of the node:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph {
a [< red] -> b -- {c [> blue], d [> "bar"']};
};
@@ -313,7 +316,7 @@ apply to the ``outgoing'' edges of the node:
This syntax allows you to easily create trees with special edge labels as in
the following example of a treap:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz
\graph [edge quotes={fill=white,inner sep=1pt},
grow down, branch right, nodes={circle,draw}] {
@@ -340,7 +343,7 @@ part of a graph than have already been defined prior to the use of the |graph|
command. For this, simply surround a node name by parentheses. This will cause
a reference to be created to an already existing node:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz {
\node (a) at (0,0) {A};
\node (b) at (1,0) {B};
@@ -355,7 +358,7 @@ to belong to a \emph{node set} by adding the option |set=|\meta{node set name}.
Then, inside a |graph| command, you can collectively refer to these nodes by
surrounding the node set name in parentheses:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,shapes.geometric}}]
\tikz [new set=my nodes] {
\node [set=my nodes, circle, draw] at (1,1) {A};
\node [set=my nodes, rectangle, draw] at (1.5,0) {B};
@@ -375,11 +378,11 @@ To facilitate specifying such graphs, you can define a \emph{graph macro}. Once
a graph macro has been defined, you can use the name of the graph to make a
copy of the graph part of the graph currently being specified:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph K_n [n=6, clockwise] };
\end{codeexample}
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph C_n [n=5, clockwise] -> mid };
\end{codeexample}
@@ -406,7 +409,7 @@ saying |complete bipartite={red}{green}| will cause edges to be added between
all red and all green nodes. More advanced connectors, like the |butterfly|
connector, allow you to add edges between color classes in a fancy manner.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz [x=8mm, y=6mm, circle]
\graph [nodes={fill=blue!70}, empty nodes, n=8] {
subgraph I_n [name=A] --[butterfly={level=4}]
@@ -480,7 +483,7 @@ like, say, |plot| or |--|.
This option causes the \meta{options} to be applied to each newly
created node inside the \meta{group specification}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [nodes=red] { a -> b -> c };
\end{codeexample}
%
@@ -491,7 +494,7 @@ like, say, |plot| or |--|.
This option causes the \meta{options} to be applied to each newly
created edge inside the \meta{group specification}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [edges={red,thick}] { a -> b -> c };
\end{codeexample}
%
@@ -506,13 +509,13 @@ like, say, |plot| or |--|.
This key specifies that the \meta{node specification} should be added
to each newly created edge as an implicitly placed node.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [edge node={node [red, near end] {X}}] { a -> b -> c };
\end{codeexample}
%
Again, multiple uses of this key accumulate.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [edge node={node [near end] {X}},
edge node={node [near start] {Y}}] { a -> b -> c };
\end{codeexample}
@@ -523,7 +526,7 @@ like, say, |plot| or |--|.
The net effect is that the |text| is placed next to the newly created
edges.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [edge label=x] { a -> b -> {c,d} };
\end{codeexample}
\end{key}
@@ -531,7 +534,7 @@ like, say, |plot| or |--|.
\begin{key}{/tikz/graphs/edge label'=\meta{text}}
This key is an abbreviation for |edge node=node[auto,swap]{|\meta{text}|}|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [edge label=out, edge label'=in]
{ subgraph C_n [clockwise, n=5] };
\end{codeexample}
@@ -558,7 +561,7 @@ ignored by the parser.
In the following example, the group specification consists of three chain
specifications, namely of |a -> b|, then |c| alone, and finally |d -> e -> f|:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> b,
c;
@@ -574,7 +577,7 @@ Commas are used to detect where chain specifications end. However, you will
often wish to use a comma also inside the options of a single node like in the
following example:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a [red, draw] -> b [blue, draw],
c [brown, draw, circle]
@@ -593,7 +596,7 @@ difference whether the options are passed to the |graph| command or whether
they are given at the beginning of this group. However, for groups nested
inside other groups, it does make a difference:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> { [nodes=red] % the option is local to these nodes:
b, c
@@ -610,7 +613,7 @@ specification} would normally go. In this case, the |\foreach| statement is
executed and for each iteration the content of the statement's body is treated
and parsed as a new chain specification.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [math nodes, branch down=5mm] {
a -> {
\foreach \i in {1,2,3} {
@@ -644,7 +647,7 @@ group.
allows you to say, for instance, |parse/.expand once| to insert the text
stored in some macro into the group.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\def\mychain{ a -> b -> c; }
\tikz \graph { [parse/.expand once=\mychain] d -> e };
\end{codeexample}
@@ -652,7 +655,7 @@ group.
In the following, more fancy example we use a loop to create a chain of
dynamic length.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\def\mychain#1{
\def\mytext{1}
\foreach \i in {2,...,#1} {
@@ -765,13 +768,13 @@ written |->| between them. Then the following happens:
no special anchor is used (which is the default). The \meta{anchor}
is stored in the macro |\tikzgraphleftanchor| with a leading dot.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{a,b,c} -> [complete bipartite] {e,f,g}
};
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [left anchor=east, right anchor=west] {
{a,b,c} -- [complete bipartite] {e,f,g}
};
@@ -826,7 +829,7 @@ written |->| between them. Then the following happens:
Here is an example that shows the default rendering of the different edge
specifications:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=5mm] {
a -> b;
c -- d;
@@ -888,7 +891,7 @@ name was already used inside the current graph. If this is the case, then we
say that the already existing node is \emph{referenced}; otherwise we say that
the node is \emph{fresh}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> b; % both are fresh
c -> a; % only c is fresh, a is referenced
@@ -915,7 +918,7 @@ be modified by using the following keys:
name is chosen is follows: An apostrophe (|'|) is appended repeatedly until
a node name is found that has not yet been used:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=5mm] {
{ [fresh nodes]
a -> {
@@ -939,7 +942,7 @@ be modified by using the following keys:
\begin{key}{/tikz/graphs/number nodes sep=\meta{text} (initially \normalfont space)}
\end{key}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=5mm] {
{ [number nodes]
a -> {
@@ -984,7 +987,7 @@ is called. The different parameters are as follows:
node name}. Repeated calls of this key accumulate, leading to
ever-longer ``name paths'':
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}
\graph {
{ [name=first] 1, 2, 3} --
@@ -1009,7 +1012,7 @@ is called. The different parameters are as follows:
the \meta{node name}. The default is |\space|, resulting in a
space.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}
\graph [name separator=] { % no separator
{ [name=first] 1, 2, 3} --
@@ -1019,7 +1022,7 @@ is called. The different parameters are as follows:
\end{tikzpicture}
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}
\graph [name separator=-] {
{ [name=first] 1, 2, 3} --
@@ -1051,7 +1054,7 @@ is called. The different parameters are as follows:
provide a text for the node that differs arbitrarily from the name
of the node.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a [as=$x$] -- b [as=$y_5$] -> c [red, as={a--b}] };
\end{codeexample}
%
@@ -1098,7 +1101,7 @@ is called. The different parameters are as follows:
useful to change this: For instance, you might wish that the text of
all graph nodes is, say, surrounded by parentheses:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [typeset=(\tikzgraphnodetext)]
{ a -> b -> c };
\end{codeexample}
@@ -1106,7 +1109,7 @@ is called. The different parameters are as follows:
A more advanced macro might take apart the node text and render it
differently:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\def\mytypesetter{\expandafter\myparser\tikzgraphnodetext\relax}
\def\myparser#1 #2 #3\relax{%
$#1_{#2,\dots,#3}$
@@ -1121,7 +1124,7 @@ is called. The different parameters are as follows:
Just sets |typeset| to nothing, which causes all nodes to have an
empty text (unless, of course, the |as| option is used):
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [empty nodes, nodes={circle, draw}] { a -> {b, c} };
\end{codeexample}
\end{key}
@@ -1130,7 +1133,7 @@ is called. The different parameters are as follows:
Sets |typeset| to |$\tikzgraphnodetext$|, which causes all nodes
names to be typeset in math mode:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [math nodes, nodes={circle, draw}] { a_1 -> {b^2, c_3^n} };
\end{codeexample}
\end{key}
@@ -1149,7 +1152,7 @@ for details.
a node is surrounded by quotation marks, you can use all sorts of special
symbols as part of the text that are normally forbidden:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}
\graph [grow right=2cm] {
"Hi, World!" -> "It's \emph{important}!"[red,rotate=-45];
@@ -1251,7 +1254,7 @@ effect is the same as if instead of the reference to the set name you had
created a group specification containing a list of references to all the nodes
that are part of the node set.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}[new set=red, new set=green, shorten >=2pt]
\foreach \i in {1,2,3} {
\node [draw, red!80, set=red] (r\i) at (\i,1) {$r_\i$};
@@ -1276,7 +1279,7 @@ access them as if they had been defined inside the graph. Here is an example
showing how you can create nodes outside a |graph| command and then connect
them inside as if they had been declared inside:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}[new set=import nodes]
\begin{scope}[nodes={set=import nodes}] % make all nodes part of this set
\node [red] (a) at (0,1) {$a$};
@@ -1298,7 +1301,7 @@ should go, you can also instead provide a group specification. Since nodes
specifications are part of chain specifications, which in turn are part of
group specifications, this is a recursive definition.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> {b,c,d} -> {e -> {f,g}, h} };
\end{codeexample}
@@ -1334,7 +1337,7 @@ several nodes have the same label.
%
In total, this is exactly the behaviour you would expect of a trie:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [trie] {
a -> {
a,
@@ -1350,7 +1353,7 @@ several nodes have the same label.
libraries, which need Lua\TeX.
%
\ifluatex
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing}\usegdlibrary{layered}}]
\tikz \graph [trie, simple, layered layout] {
a -> b -> a,
a -> b -> c,
@@ -1361,7 +1364,7 @@ several nodes have the same label.
In the following example, we setup the |typeset| key so that it shows the
complete names of the nodes:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing}\usegdlibrary{layered}}]
\tikz \graph [trie, simple, layered layout,
typeset=\tikzgraphnodefullname] {
a -> b -> a,
@@ -1374,7 +1377,7 @@ several nodes have the same label.
You can also use the |trie| key locally and later reference nodes using
their full name:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ [trie, simple]
a -> {
@@ -1456,11 +1459,11 @@ large, algorithmically generated graphs.
Here is a typical way this syntax might be used:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph [quick] { "a" --["foo"] "b"[x=1] };
\end{codeexample}
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [quick] {
"a"/"$a$" -- "b"[x=1] --[red] "c"[x=2];
{ [nodes=blue] "a" -- "d"[y=1]; };
@@ -1487,7 +1490,7 @@ large, algorithmically generated graphs.
\subsection{Simple Versus Multi-Graphs}
\label{section-library-graphs-simple}
-The |graph| library allows you to construct both simple graphs and
+The |graphs| library allows you to construct both simple graphs and
multi-graphs. In a simple graph there can be at most one edge between any two
vertices, while in a multi-graph there can be multiple edges (hence the name).
The two keys |multi| and |simple| allow you to switch (even locally inside on
@@ -1501,7 +1504,7 @@ construct.
part is a multi-graph), then when you specify an edge between two nodes
several times, several such edges get created:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [multi] { % "multi" is not really necessary here
a ->[bend left, red] b;
a ->[bend right, blue] b;
@@ -1523,7 +1526,7 @@ construct.
In contrast a multi-graph, in a simple graph, at most one edge gets created
for every pair of vertices:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [simple]{
a ->[bend left, red] b;
a ->[bend right, blue] b;
@@ -1539,7 +1542,7 @@ construct.
create a complicated graph and then later redirect and otherwise modify
edges easily:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [simple, grow right=2cm] {
{a,b,c,d} ->[complete bipartite] {e,f,g,h};
@@ -1554,7 +1557,7 @@ construct.
superfluous. In a simple graph, however, it counts as an edge kind and you
can thus use it to remove an edge that been added previously:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple] {
subgraph K_n [n=8, clockwise];
% Get rid of the following edges:
@@ -1588,7 +1591,7 @@ construct.
\subsection{Graph Edges: Labeling and Styling}
-When the |graph| library creates an edge between two nodes in a graph, the
+When the |graphs| library creates an edge between two nodes in a graph, the
appearance (called ``styling'' in \tikzname) can be specified in different
ways. Sometimes you will simply wish to say ``the edges between these two
groups of node should be red'', but sometimes you may wish to say ``this
@@ -1607,7 +1610,7 @@ chain group before the |->| and the nodes in the chain group following it. The
library and you write some text in quotes inside the |options|, this text will
be added as a label to each edge:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz
\graph [edge quotes=near start] {
{ a, b } -> [red, "x", complete bipartite] { c, d };
@@ -1618,7 +1621,7 @@ As documented in the |quotes| library in more detail, you can easily modify the
appearance of edge labels created using the quotes syntax by adding options
after the closing quotes:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph {
a ->["x"] b ->["y"'] c ->["z" red] d;
};
@@ -1628,19 +1631,20 @@ The following options make it easy to setup the styling of nodes created in
this way:
%
\begin{key}{/tikz/graphs/edge quotes=\opt{\meta{options}}}
- A shorthand for setting the style |every edge quotes| to \meta{options}.
-\begin{codeexample}[]
+ A shorthand for setting the style |every edge quotes| to \meta{options}.
+ %
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph [edge quotes={blue,auto}] {
a ->["x"] b ->["y"'] c ->["b" red] d;
};
\end{codeexample}
-%
+ %
\end{key}
\begin{key}{/tikz/graphs/edge quotes center}
A shorthand for |edge quotes| to |anchor=center|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph [edge quotes center] {
a ->["x"] b ->["y"] c ->["z" red] d;
};
@@ -1651,7 +1655,7 @@ this way:
\begin{key}{/tikz/graphs/edge quotes mid}
A shorthand for |edge quotes| to |anchor=mid|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph [edge quotes mid] {
a ->["x"] b ->["y"] c ->["z" red] d;
};
@@ -1664,7 +1668,7 @@ this way:
Consider the following tree-like graph:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> {b,c} };
\end{codeexample}
@@ -1676,7 +1680,7 @@ one of these option |red| or |blue| to the operator.
There are several ways to solve this problem. First, we can simply split up the
specification and specify the two edges separately:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a -> [red] b;
a -> [blue] c;
@@ -1695,7 +1699,7 @@ One can sidestep this problem using the |simple| option: This option allows you
to first specify a graph and then, later on, replace edges by other edges and,
thereby, provide new options:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [simple] {
a -> {b,c};
a -> [red] b;
@@ -1711,7 +1715,7 @@ path in a larger tree: First specify the tree normally and, then, ``respecify''
the path or paths with some other edge options in force. In the following
example, we use this to highlight a whole subtree of a larger tree:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [simple] {
% The larger tree, no special options in force
a -> {
@@ -1737,7 +1741,7 @@ red edge between |a| and |b| and a blue edge between |a| and |c|, this could
also be phrased as follows: ``Make the edge leading to |b| red and make the
edge leading to |c| blue''.
-For this situation, the |graph| library offers a number of special keys, which
+For this situation, the |graphs| library offers a number of special keys, which
are documented in the following. However, most of the time you will not use
these keys directly, but, rather, use a special syntax explained in
Section~\ref{section-syntax-outgoing-incoming}.
@@ -1748,7 +1752,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
that is created by a connector like |->| in which the node is a
\emph{target}. Consider the following example:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } ->
{ c [target edge style=red], d } ->
@@ -1762,7 +1766,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
When an edge already has options set directly, the \meta{options} are
executed after these direct options, thus, they ``overrule'' them:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } -> [blue, thick]
{ c [target edge style=red], d } ->
@@ -1774,7 +1778,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
for edges created later on that lead to the node will have these options
set:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } ->
{ c [target edge style=red], d } ->
@@ -1793,7 +1797,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
also edge labels (see below) for this node.
\end{key}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } ->
{ c [target edge style=red], d },
@@ -1808,7 +1812,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
will not be added as options to any newly created edges with the current
node as their target, but rather it will be added as a node specification.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } ->
{ c [target edge node=node{X}], d } ->
@@ -1825,7 +1829,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
Works exactly like |target edge style|, only now the \meta{options} are
only added when the node is a source of a newly created edge:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{ a, b } ->
{ c [source edge style=red], d } ->
@@ -1844,7 +1848,7 @@ Section~\ref{section-syntax-outgoing-incoming}.
|target node style|.
\end{enumerate}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
a [source edge style=red] ->[green]
b [target edge style=blue] % blue wins
@@ -1902,7 +1906,7 @@ target and source options:
These mechanisms make it especially easy to create trees in which the edges are
labeled in some special way:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz
\graph [edge quotes={fill=white,inner sep=1pt},
grow down, branch right] {
@@ -1924,7 +1928,7 @@ instance when drawing certain kind of trees, the nodes themselves should not
get any text, but rather the edge leading to the node should be labeled as in
the following example:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,quotes}}]
\tikz \graph [empty nodes]
{
root -> {
@@ -1959,7 +1963,7 @@ The following styles do exactly this:
%
Here is an example that show how this command is used.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [put node text on incoming edges,
math nodes, nodes={circle,draw}]
{ a -> b -> {c, d} };
@@ -2015,7 +2019,7 @@ key:
encompassing scopes, unless it is explicitly changed (see below) or
unset (again, see below).
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red] {
[cycle=red] % causes all "logically" red nodes to be connected in
% a cycle
@@ -2026,7 +2030,7 @@ key:
};
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red, color class=green,
math nodes, clockwise, n=5] {
[complete bipartite={red}{green}]
@@ -2041,7 +2045,7 @@ key:
the color \meta{color class name}. You can also use |!|\meta{color
class name} as an alias for this key.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red, color class=green,
math nodes, clockwise, n=5] {
[complete bipartite={red}{green}]
@@ -2057,7 +2061,7 @@ key:
color} instead. They loose having color \meta{color class name}, but
other colors are not affected.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red, color class=green,
math nodes, clockwise, n=5] {
[complete bipartite={red}{green}]
@@ -2082,12 +2086,13 @@ The following color classes are available by default:
saying |not source| or |not target| with a node, you can influence how
it is connected:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> { b, c, d } -> e };
- \end{codeexample}
- \begin{codeexample}[]
+\end{codeexample}
+ %
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> { b[not source], c, d[not target] } -> e };
- \end{codeexample}
+\end{codeexample}
%
\item Color classes |source'| and |target'|. These are temporary colors
that are also explained in Section~\ref{section-library-graphs-join}.
@@ -2150,7 +2155,7 @@ simply add edges between all nodes of the group.
\begin{key}{/tikz/graphs/--}
Sets the |default edge kind| to |--|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph K_n [--, n=5, clockwise, radius=6mm] };
\end{codeexample}
\end{key}
@@ -2158,7 +2163,7 @@ simply add edges between all nodes of the group.
\begin{key}{/tikz/graphs/->}
Sets the |default edge kind| to |->|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph K_n [->, n=5, clockwise, radius=6mm] };
\end{codeexample}
\end{key}
@@ -2166,7 +2171,7 @@ simply add edges between all nodes of the group.
\begin{key}{/tikz/graphs/<-}
Sets the |default edge kind| to |<-|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph K_n [<-, n=5, clockwise, radius=6mm] };
\end{codeexample}
\end{key}
@@ -2174,7 +2179,7 @@ simply add edges between all nodes of the group.
\begin{key}{/tikz/graphs/<->}
Sets the |default edge kind| to |<->|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph K_n [<->, n=5, clockwise, radius=6mm] };
\end{codeexample}
\end{key}
@@ -2199,7 +2204,7 @@ simply add edges between all nodes of the group.
In the following example we use an operator to connect every node
colored |all| inside the subgroup to he node |root|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\def\myconnect#1{\tikzset{graphs/new ->={root}{#1}{}{}}}
\begin{tikzpicture}
@@ -2232,7 +2237,7 @@ simply add edges between all nodes of the group.
As an example, let us create an operator then adds a zig-zag path
between two color classes:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\newcount\leftshorecount \newcount\rightshorecount
\newcount\mycount \newcount\myothercount
\def\zigzag{
@@ -2336,7 +2341,7 @@ them) are connected to the sources of |{d,e->f}| (which are just |d| and~|e|).
Finally, in the whole graph only |a|, |b|, and |c| are sources while only |d|
and |f| are targets.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\def\hilightsource#1{\fill [green, opacity=.25] (#1) circle [radius=2mm]; }
\def\hilighttarget#1{\fill [red, opacity=.25] (#1) circle [radius=2mm]; }
\tikz \graph
@@ -2385,7 +2390,7 @@ determine which operator should be chosen for performing this job:
\meta{edge specification} whose \meta{options} do not contain the
|operator| key.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [default edge operator=matching] {
{a, b} ->[matching and star]
{c, d, e} --[complete bipartite]
@@ -2414,7 +2419,7 @@ with an edge specification, it can also be used as a normal operator together
with a group specification. In this case, however, the color classes must be
named explicitly:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\begin{tikzpicture}
\graph [color class=red, color class=green, math nodes]
{ [complete bipartite={red}{green}]
@@ -2461,7 +2466,7 @@ A graph macro is declared using the following key:
with some \meta{options}, they are executed prior to inserting the
\meta{specification}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=4mm, declare={claw}{1 -- {2,3,4}}] {
a;
claw;
@@ -2471,7 +2476,7 @@ A graph macro is declared using the following key:
%
In the next example, we use a key to configure a subgraph:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [ n/.code=\def\n{#1}, branch down=4mm,
declare={star}{root -- { \foreach \i in {1,...,\n} {\i} }}]
{ star [n=5]; };
@@ -2481,7 +2486,7 @@ A graph macro is declared using the following key:
As a last example, let us define a somewhat more complicated graph macro.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\newcount\mycount
\tikzgraphsset{
levels/.store in=\tikzgraphlevel,
@@ -2514,7 +2519,7 @@ Note that when you use a graph macro several time inside the same graph, you
will typically have to use the |name| option so that different copies of the
subgraph are created:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=4mm, declare={claw}{1 -- {2,3,4}}] {
claw [name=left],
claw [name=right]
@@ -2528,14 +2533,14 @@ Section~\ref{section-library-graphs-reference-macros}.
\subsection{Online Placement Strategies}
\label{section-library-graphs-placement}
-The main job of the |graph| library is to make it easy to specify which nodes
+The main job of the |graphs| library is to make it easy to specify which nodes
are present in a graph and how they are connected. In contrast, it is
\emph{not} the primary job of the library to compute good positions for nodes
in a graph -- use for instance a |\matrix|, specify good positions ``by hand''
or use the graph drawing facilities. Nevertheless, some basic support for
-automatic node placement is provided for simple cases. The graph library will
-provide you with information about the position of nodes inside their groups
-and chains.
+automatic node placement is provided for simple cases. The |graphs| library
+will provide you with information about the position of nodes inside their
+groups and chains.
As a graph is being constructed, a \emph{placement strategy} is used to
determine a (reasonably good) position for the nodes as they are created. These
@@ -2562,7 +2567,7 @@ work together in perfect harmony.
this strategy if you position nodes ``by hand''. For this, you can use the
|at| key, the |shift| keys:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [no placement]
{
a[at={(0:0)}] -> b[at={(1,0)}] -> c[yshift=1cm];
@@ -2577,7 +2582,7 @@ work together in perfect harmony.
written |at={(|\meta{x dimension}|,|\meta{y dimension}|)}|, where
\meta{y dimension} is a value set using the |y| key:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [no placement]
{
a[x=0,y=0] -> b[x=1,y=0] -> c[x=0,y=1];
@@ -2587,7 +2592,7 @@ work together in perfect harmony.
Note that you can specify an |x| or a |y| key for a whole scope and
then vary only the other key:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [no placement]
{
a ->
@@ -2622,10 +2627,10 @@ work together in perfect harmony.
This slightly confusing explanation is perhaps best exemplified. In the
below example, the two numbers indicate the two logical width and depth of
- each node as computed by the |graph| library. Just ignore the arcane code
+ each node as computed by the |graphs| library. Just ignore the arcane code
that is used to print these numbers.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz
\graph [nodes={align=center, inner sep=1pt}, grow right=7mm,
typeset={\tikzgraphnodetext\\[-4pt]
@@ -2656,7 +2661,7 @@ work together in perfect harmony.
Under the regime of the |Cartesian placement| strategy, each node is
shifted by the current logical width times this \meta{coordinate}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [chain shift=(45:1)] {
a -> b -> c;
d -> e;
@@ -2669,7 +2674,7 @@ work together in perfect harmony.
Like for |chain shift|, each node is shifted by the current logical
depth times this \meta{coordinate}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [chain shift=(45:7mm), group shift=(-45:7mm)] {
a -> b -> c;
d -> e;
@@ -2680,11 +2685,11 @@ work together in perfect harmony.
\end{key}
\begin{key}{/tikz/graphs/grow up=\meta{distance} (default 1)}
- Sets the |chain shift| to |(|\meta{distance}|,0)|, so that chains ``grow
+ Sets the |chain shift| to |(0,|\meta{distance}|)|, so that chains ``grow
upward''. The distance by which the center of each new element is removed
from the center of the previous one is \meta{distance}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow up=7mm] { a -> b -> c};
\end{codeexample}
%
@@ -2693,7 +2698,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/grow down=\meta{distance} (default 1)}
Like |grow up|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow down=7mm] { a -> b -> c};
\end{codeexample}
%
@@ -2702,7 +2707,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/grow left=\meta{distance} (default 1)}
Like |grow up|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow left=7mm] { a -> b -> c};
\end{codeexample}
%
@@ -2711,7 +2716,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/grow right=\meta{distance} (default 1)}
Like |grow up|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow right=7mm] { a -> b -> c};
\end{codeexample}
%
@@ -2722,7 +2727,7 @@ work together in perfect harmony.
which the center of each new element is removed from the center of the
previous one is \meta{distance}.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch up=7mm] { a -> b -> {c, d, e} };
\end{codeexample}
%
@@ -2733,7 +2738,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/branch down=\meta{distance} (default 1)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch down=7mm] { a -> b -> {c, d, e}};
\end{codeexample}
%
@@ -2741,7 +2746,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/branch left=\meta{distance} (default 1)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch left=7mm, grow down=7mm] { a -> b -> {c, d, e}};
\end{codeexample}
%
@@ -2749,7 +2754,7 @@ work together in perfect harmony.
\begin{key}{/tikz/graphs/branch right=\meta{distance} (default 1)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch right=7mm, grow down=7mm] { a -> b -> {c, d, e}};
\end{codeexample}
%
@@ -2766,17 +2771,17 @@ The following keys place nodes in a $N\times M$ grid.
automatically as $\sqrt{\texttt{\string|V\string|}}$. $N$ is the number of
rows needed to lay out the graph in a grid with $M$ columns.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
% An example with 6 nodes, 3 columns and therefor 2 rows
\tikz \graph [grid placement] { subgraph I_n[n=6, wrap after=3] };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
% An example with 9 nodes with columns and rows computed automatically
\tikz \graph [grid placement] { subgraph Grid_n [n=9] };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
% Directions can be changed
\tikz \graph [grid placement, branch up, grow left] { subgraph Grid_n [n=9] };
\end{codeexample}
@@ -2784,7 +2789,7 @@ The following keys place nodes in a $N\times M$ grid.
In case a user-defined graph instead of a pre-defined |subgraph| is to be
laid out using |grid placement|, |n| has to be specified explicitly:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grid placement] {
[n=6, wrap after=3]
a -- b -- c -- d -- e -- f
@@ -2809,7 +2814,7 @@ or advanced offline strategies to place the nodes.
along a chain are placed in such a way that the left end of a new node is
\meta{distance} from the right end of the previous node:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow right sep, left anchor=east, right anchor=west] {
start -- {
long text -- {short, very long text} -- more text,
@@ -2828,14 +2833,15 @@ or advanced offline strategies to place the nodes.
\begin{key}{/tikz/graphs/grow left sep=\meta{distance} (default 1em)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow left sep] { long -- longer -- longest };
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/graphs/grow up sep=\meta{distance} (default 1em)}
-\begin{codeexample}[]
+%
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow up sep] {
a / $a=x$ --
b / {$b=\displaystyle \int_0^1 x dx$} --
@@ -2853,7 +2859,7 @@ or advanced offline strategies to place the nodes.
This key works like |grow right sep|, only it affects groups rather than
chains.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow down, branch right sep] {
start -- {
an even longer text -- {short, very long text} -- more text,
@@ -2869,7 +2875,7 @@ or advanced offline strategies to place the nodes.
\begin{key}{/tikz/graphs/branch left sep=\meta{distance} (default 1em)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow down sep, branch left sep] {
start -- {
an even longer text -- {short, very long text} -- more text,
@@ -2883,7 +2889,7 @@ or advanced offline strategies to place the nodes.
\begin{key}{/tikz/graphs/branch up sep=\meta{distance} (default 1em)}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [branch up sep] { a, b, c[draw, circle, inner sep=7mm] };
\end{codeexample}
%
@@ -2910,7 +2916,7 @@ or |counterclockwise|.
chain is shifted by
|(|\meta{logical width}\meta{angle}|:|\meta{logical width}\meta{angle}|)|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement] {
a -> b -> c;
d -> e;
@@ -2924,7 +2930,7 @@ or |counterclockwise|.
Like for |group shift|, each node on a chain is shifted by
|(|\meta{logical depth}\meta{angle}|:|\meta{logical depth}\meta{angle}|)|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement, group polar shift=(30:0)] {
a -> b -> c;
d -> e;
@@ -2932,7 +2938,7 @@ or |counterclockwise|.
};
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement,
chain polar shift=(30:0),
group polar shift=(0:1cm)] {
@@ -2948,11 +2954,11 @@ or |counterclockwise|.
when the polar shift of a node has been calculated. Essentially, this
key allows you to set the \meta{radius} of the innermost circle.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement, radius=5mm] { a, b, c, d };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement, radius=1cm] { a, b, c, d };
\end{codeexample}
\end{key}
@@ -2961,11 +2967,11 @@ or |counterclockwise|.
This is an initial value that is added to the total computed angle when
the polar shift of a node has been calculated.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement] { a, b, c, d };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [circular placement, phase=0] { a, b, c, d };
\end{codeexample}
\end{key}
@@ -2979,11 +2985,11 @@ or |counterclockwise|.
which is exactly what you want when you use predefined graph macros like
|subgraph K_n|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [clockwise=4] { a, b, c, d };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [clockwise] { subgraph K_n [n=5] };
\end{codeexample}
%
@@ -3006,7 +3012,7 @@ the node inside this tree.
This key stores a number that is increased for each element on a chain, but
gets reset at the end of a group:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [ branch down=5mm, typeset=
\tikzgraphnodetext:\pgfkeysvalueof{/tikz/graphs/placement/level}]
{
@@ -3039,7 +3045,7 @@ command also executes the following keys whenever it creates a node:
This key also gets executed for each newly created node with \meta{level}
set to the current level of the node.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [
branch down=5mm,
level 1/.style={nodes=red},
@@ -3058,7 +3064,7 @@ command also executes the following keys whenever it creates a node:
};
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [
branch down=5mm,
level 1/.style={grow right=2cm},
@@ -3086,7 +3092,7 @@ command also executes the following keys whenever it creates a node:
In the following the details of how to define a new placement strategy are
explained. Most readers may wish to skip this section.
-As a graph specification is being parsed, the |graph| library will keep track
+As a graph specification is being parsed, the |graphs| library will keep track
of different numbers that identify the positions of the nodes. Let us start
with what happens on a chain. First, the following counter is increased for
each element of the chain:
@@ -3096,7 +3102,7 @@ each element of the chain:
current chain. However, you only have access to this value inside the code
passed to the macro |compute position|, explained later on.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [
grow right sep, typeset=\tikzgraphnodetext:\mynum,
placement/compute position/.append code=
@@ -3142,7 +3148,7 @@ gives more interesting information:
just setup things so that the computed width and depth of each node is
displayed at the bottom of each node.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz
\graph [nodes={align=center, inner sep=1pt}, grow right=7mm,
typeset={\tikzgraphnodetext\\[-4pt]
@@ -3166,7 +3172,7 @@ gives more interesting information:
option, which internally sets the |logical node width| key so that it
returns the width of its parameter in points.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz
\graph [grow right sep, branch down sep, nodes={align=left, inner sep=1pt},
typeset={\tikzgraphnodetext\\[-4pt] \tiny Width: \mywidth\\[-6pt] \tiny Depth: \mydepth},
@@ -3190,11 +3196,11 @@ Symmetrically to chains, as a group is being constructed, counters are
available for the number of chains encountered so far in the current group and
for the logical depth of the current group:
%
-\begin{key}{/tikz/graphs/placement/element count}
+\begin{key}{/tikz/graphs/placement/chain count}
This key stores a number that tells us the sequence number of the
chain in the current group.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [
grow right sep, branch down=5mm, typeset=\tikzgraphnodetext:\mynum,
placement/compute position/.append code=
@@ -3246,7 +3252,7 @@ following two keys:
(Naturally, the same effect could be achieved much more easily using the
|level| key.)
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\newcount\mycount
\def\lightendeepernodes{
\pgfmathsetcount{\mycount}{
@@ -3321,7 +3327,7 @@ following two keys:
|V={1,...,|\meta{number}|}, name shore V/.style={name=V}|.
\end{key}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [branch right, nodes={draw, circle}]
{ subgraph I_n [V={a,b,c}] };
\end{codeexample}
@@ -3330,7 +3336,7 @@ following two keys:
used to introduce nodes into a graph that are then connected as in the
following example:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [clockwise, clique] { subgraph I_n [n=4] };
\end{codeexample}
%
@@ -3341,7 +3347,7 @@ following two keys:
$m$ unconnected vertices. The first set consists of the vertices set by the
key |V|, the other set consists of the vertices set by the key |W|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph { subgraph I_nm [V={1,2,3}, W={a,b,c}] };
\end{codeexample}
%
@@ -3371,7 +3377,7 @@ following two keys:
The main purpose of this subgraph is to setup the nodes in a bipartite
graph:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph {
subgraph I_nm [n=3, m=4];
@@ -3386,7 +3392,7 @@ following two keys:
\begin{graph}{subgraph K\_n}
This graph is the complete clique on the vertices from the |V| key.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [clockwise] { subgraph K_n [n=7] };
\end{codeexample}
%
@@ -3396,12 +3402,12 @@ following two keys:
This graph is the complete bipartite graph with the two shores |V| and |W|
as in |subgraph I_nm|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [branch right, grow down]
{ subgraph K_nm [V={6,...,9}, W={b,...,e}] };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple, branch right, grow down]
{
subgraph K_nm [V={1,2,3}, W={a,b,c,d}, ->];
@@ -3414,7 +3420,7 @@ following two keys:
\begin{graph}{subgraph P\_n}
This graph is the path on the vertices in |V|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [branch right] { subgraph P_n [n=3] };
\end{codeexample}
%
@@ -3423,7 +3429,7 @@ following two keys:
\begin{graph}{subgraph C\_n}
This graph is the cycle on the vertices in |V|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [clockwise] { subgraph C_n [n=7, ->] };
\end{codeexample}
%
@@ -3439,12 +3445,12 @@ following two keys:
created between the nodes of a |Grid_n| |subgraph| using different
values for |wrap after|.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [grid placement] { subgraph Grid_n [n=3,wrap after=1] };
\tikz \graph [grid placement] { subgraph Grid_n [n=3,wrap after=3] };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [grid placement] { subgraph Grid_n [n=4,wrap after=2] };
\tikz \graph [grid placement] { subgraph Grid_n [n=4] };
\end{codeexample}
@@ -3464,7 +3470,7 @@ following two keys:
% The names of the two shores |V| and |W| can be changed as described in
% the documentation of the keys |/tikz/graphs/name shore V| and
% |/tikz/graphs/name shore W|.
-% \begin{codeexample}[]
+% \begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
%\tikz \graph [grid placement] { subgraph Grid_nm [V={1,2,3}, W={4, 5, 6}] };
% \end{codeexample}
%\end{graph}
@@ -3481,7 +3487,7 @@ vertices of the current group having a certain color in a specific way.
a color that all nodes get by default, when you do not specify anything,
all nodes will be connected.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [clockwise, n=5] {
a,
b,
@@ -3492,7 +3498,7 @@ vertices of the current group having a certain color in a specific way.
};
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red, clockwise, n=5] {
[clique=red, ->]
a, b[red], c[red], d, e[red]
@@ -3506,7 +3512,8 @@ vertices of the current group having a certain color in a specific way.
current group having belonging to color class \meta{color}. More precisely,
an edge of kind |-!-| is added for each pair of vertices. This means that
edge only get removed if you specify the |simple| option.
-\begin{codeexample}[]
+ %
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple] {
subgraph K_n [<->, n=7, clockwise]; % create lots of edges
@@ -3520,7 +3527,7 @@ vertices of the current group having a certain color in a specific way.
Connects the nodes colored \meta{color} is a cyclic fashion. The ordering
is the ordering in which they appear in the whole graph specification.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [clockwise, n=6, phase=60] {
{ [cycle, ->] a, b, c },
{ [cycle, <-] d, e, f }
@@ -3534,7 +3541,7 @@ vertices of the current group having a certain color in a specific way.
all other edges between the nodes of the cycle, provided we are
constructing a |simple| graph.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple] {
subgraph K_n [n=7, clockwise]; % create lots of edges
@@ -3548,7 +3555,7 @@ vertices of the current group having a certain color in a specific way.
Works like |cycle|, only there is no edge from the last to the first
vertex.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [clockwise, n=6] {
{ [path, ->] a, b, c },
{ [path, <-] d, e, f }
@@ -3561,7 +3568,7 @@ vertices of the current group having a certain color in a specific way.
Works like |induced cycle|, only there is no edge from the last to the
first vertex.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple] {
subgraph K_n [n=7, clockwise]; % create lots of edges
@@ -3582,14 +3589,14 @@ the colors need to be set explicitly).
Adds all possible edges from every node having color \meta{from color} to
every node having color \meta{to color}:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { {a, b} ->[complete bipartite]
{c, d, e} --[complete bipartite]
{g, h, i, j} --[complete bipartite]
k };
\end{codeexample}
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [color class=red, color class=green, clockwise, n=6] {
[complete bipartite={red}{green}, ->]
a [red], b[red], c[red], d[green], e[green], f[green]
@@ -3603,7 +3610,7 @@ the colors need to be set explicitly).
edges between the vertices in either shore are removed (more precisely,
they get replaced by |-!-| edges).
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [simple] {
subgraph K_n [n=5, clockwise]; % Lots of edges
@@ -3622,7 +3629,7 @@ the colors need to be set explicitly).
what graph theoreticians call a \emph{perfect matching}, otherwise only a
maximum, but not perfect matching results.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph {
{a, b, c} ->[matching]
{d, e, f} --[matching]
@@ -3641,7 +3648,7 @@ the colors need to be set explicitly).
This simple rule allows for some powerful effects (since this connector is
the one initially set, there is no need to add it here):
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph { a -> {b, c} -> {d, e} -- f};
\end{codeexample}
%
@@ -3661,7 +3668,7 @@ the colors need to be set explicitly).
each node gets connected to the corresponding node in the other set with
the same index (as in a |matching|):
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs.standard}}]
\tikz \graph [left anchor=east, right anchor=west,
branch down=4mm, grow right=15mm] {
subgraph I_n [n=12, name=A] --[butterfly={level=3}]