# Layered Graph from Tikz Manual

I suppose I have quite some experience with vanilla latex (which I have used to write several documents), but I am making my first baby steps with tikz. In particular, I am trying to reproduce the diagram on page 363 of the Manual for Version 3.0.1a by Till Tantau. I suppose I am not setting up my environment correctly. Here is the code I am using (a copy and paste from the book as far as the part after begin{document} is concerned)

 \documentclass{article} % say
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{angles}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,decorations.pathmorphing,
backgrounds,positioning,fit,petri}
\usetikzlibrary{graphs}
\usetikzlibrary{bending}
\usetikzlibrary{automata}
% \usetikzlibrary{graphdrawing,graphs}
% \usegdlibrary{layered}
\usetikzlibrary{shapes.multipart}
\begin{document}

\tikz [nodes={text height=.7em, text depth=.2em,
draw=black!20, thick, fill=white, font=\footnotesize},
>=spaced 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";
};


but this leads me to a number of errors when I pdflatex the script, in particular this one

    ! Package pgf Error: Unknown arrow tip kind 'spaced stealth’'.


However, even if I remove the stealth bit, I still get this error message

  ! Package pgfkeys Error: I do not know the key '/tikz/graphs
/layered layout' and I am going to ignore it. Perhaps you
misspelled it.


According to what I found here

How do I use TikZ graphdrawing package with KTikZ+LuaLaTeX?

it is a matter of using \usegdlibrary{layered} in the script. In that case, though, pdflatex tells me I need to resort to lualatex. Bottom line: I am very confused at this point. Any suggestions to make my life easier?

• Welcome! If you are just getting started with TikZ, I strongly recommend not starting with something this complex. The graph drawing stuff baffles me, although I'm reasonably comfortable with other aspects of TikZ. You are trying to learn TikZ and the graph-drawing stuff simultaneously and anybody would be very confused in that position. Start by working through one of the tutorials at the beginning of the manual or by trying to reproduce a diagram which does not depend on Lua or on lots of extra libraries. It's like trying to sprint the 100m before learning to crawl: harder than need be ;). – cfr Feb 7 '16 at 21:06
• But, yes. The automated graph drawing requires Lua to compute the placement of the nodes: this is not implemented in TeX, unlike the rest of TikZ. Also, arrows is older and deprecated. arrows.meta is the newer, recommended library. You are using both. That should work, but maybe needlessly confusing. What are the rest of the libraries for? Most of them seem superfluous. Make sure that you know why you are loading things. If you aren't sure, comment it out and see what breaks. (I do this regularly.) – cfr Feb 7 '16 at 21:12
• @larry77 Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – JP-Ellis Feb 20 '16 at 0:16

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 of pdflatex document.tex, or if you are using an IDE, then there should (hopefully) be an option to select lualatex 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 corresponding stealth', but no spaced 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 to spaced 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 the verbatim-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 –.)
• 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.

• Assumptions are dangerous online .... – cfr Feb 8 '16 at 2:09
• @cfr What do you mean exactly? – JP-Ellis Feb 8 '16 at 2:25
• 'Dangerous' in the sense of 'liable to lead to falsehood'. As @cfr mention in his comments.... – cfr Feb 8 '16 at 2:28
• Oh, sorry about that :/ – JP-Ellis Feb 8 '16 at 4:35
• spaced stealth is deprecated syntax based on the old arrows/arrows.spaced libraries, now replaced by arrows.meta. At least, I think so. (I read the comments at the top of the arrows.spaced library and it uses the old arrows.) – cfr Aug 4 '17 at 22:58

An addition to the answer above: The spaced stealth' can be imported using:

\usetikzlibrary{arrows.spaced}

• This is deprecated and out not be recommended with current TikZ. Use arrows.meta` instead. – cfr Aug 4 '17 at 22:55