Layered Graph from Tikz Manual
The graph drawing library is probably one of the more complex parts and on top of this, this particular diagram is a particularly complex diagram too.
Looking through your code, there are a few issues I can identify:
- Firstly, there are quite a few superfluous libraries. This is not detrimental, but not exactly recommended either;
- The graph drawing algorithms are quite complex, and implementing them in pure TeX would be unnecessarily difficult (maybe LaTeX3 might be nicer?), so they are implemented in Lua. As a result, you need to compile with LuaLaTeX to generate the output. You just need to run
lualatex document.tex
instead ofpdflatex document.tex
, or if you are using an IDE, then there should (hopefully) be an option to selectlualatex
as the compiler; - There are two issues with
spaced stealth
arrow:- Firstly, the arrow style doesn't appear to be defined anywhere in the documentation. There is
stealth
and the correspondingstealth'
, but nospaced stealth
so I actually don't know why they use it in the documentation (edit: it appears that this has been deprecated and should actually have been removed from the documentation, see comment from @cfr); - Secondly, even if it did exist, you have
spaced stealth’
which is different tospaced stealth'
(notice the slight difference in the apostrophe, they are actuall distinct unicode characters). This is a bug in the documentation at the moment whereby'
gets modified within theverbatim
-like environment as if it was a text environment. As a result, copy-pasting doesn't actually work properly at this stage. (They also had an issue whereby--
would become an en-dash–
.)
- Firstly, the arrow style doesn't appear to be defined anywhere in the documentation. There is
- You have certain newlines in the wrong place. For example, the second last line has
"System\nV.0"
. This will (most likely) interfer with the graphing algorithm as it is will treat that node as being distinct to the"System V.0"
vertex.
I would recommend that you start with simpler example. Start by getting a feel of simple layouts and then start building more and more complex layouts. For example, have a look at how the following layouts change:
a -> b -> c,
b -> d,
a -> b -> {c, d}
a -> b -> {c -> x, d}
{a, b} -> {c -> x, d}
and so on. Also have a look at how different algorithms work with each of the above layouts (layered layout
, spring layout
, etc.)
Coming back to your original example, here is the fixed code and reformatted to make it more legible:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usegdlibrary{layered}
\begin{document}
\tikz [
nodes={
text height=.7em,
text depth=.2em,
draw=black!20,
thick,
fill=white,
font=\footnotesize
},
>=stealth',
rounded corners,
semithick
]
\graph [
layered layout,
level distance=1cm,
sibling sep=.5em,
sibling distance=1cm
] {
"5th Edition" -> {"6th Edition", "PWB 1.0" };
"6th Edition" -> {
"LSX" [>child anchor=45],
"1 BSD",
"Mini Unix",
"Wollongong",
"Interdata" };
"Interdata" -> {
"Unix/TS 3.0",
"PWB 2.0",
"7th Edition" };
"7th Edition" -> {
"8th Edition",
"32V",
"V7M",
"Ultrix-11",
"Xenix",
"UniPlus+" };
"V7M" -> "Ultrix-11";
"8th Edition" -> "9th Edition";
"1 BSD" -> "2 BSD"
-> "2.8 BSD"
-> { "Ultrix-11", "2.9 BSD" };
"32V" -> "3 BSD"
-> "4 BSD"
-> "4.1 BSD"
-> { "4.2 BSD", "2.8 BSD", "8th Edition" };
"4.2 BSD" -> { "4.3 BSD", "Ultrix-32" };
"PWB 1.0" -> {
"PWB 1.2" -> "PWB 2.0",
"USG 1.0" -> {
"CB Unix 1",
"USG 2.0" }};
"CB Unix 1" -> "CB Unix 2"
-> "CB Unix 3"
-> { "Unix/TS++", "PDP-11 Sys V" };
{
"USG 2.0" -> "USG 3.0",
"PWB 2.0",
"Unix/TS 1.0"
} -> "Unix/TS 3.0";
{
"Unix/TS++",
"CB Unix 3",
"Unix/TS 3.0"
} -> "TS 4.0"
-> "System
V.0" -> "System V.2"
-> "System V.3";
};
\end{document}
and here is the corresponding output:
Note: There is an incompatibility between in the standalone
class and LuaLaTeX. Until the standalone
class is updated, you will need to add \RequirePackage{luatex85}
before the document class declaration.