# Centering nodes with Tikz automatic node placement

I would like the nodes to be centered, an I can't see a way to do this:

MWE:

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
\begin{tikzpicture}
\begin{graph}[grow down, branch right]
{a -> {b,c}};
\end{graph}
\end{tikzpicture}
\end{document}

As an aside, the grow down option seems rather broken (just take out the branch right bit in the above). Is there a way to fix that?

Note: I want to do this with Tikz automatic node placement, not something else.

• Centered in relation to what? – Qrrbrbirlbel Dec 3 '13 at 3:22
• @Qrrbrbirlbel, so that a is x centered between b and c – soandos Dec 3 '13 at 3:31

Assuming I understand what is required, then you should take a look at the documentation (in the CVS manual) about graph layouts, in particular the tree layout:

\documentclass[tikz,border=0.125cm]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees}
\begin{document}
\tikz\graph [tree layout, grow down]
{a -> {b,c}};
\end{document}

• How can I do this in LaTeX? (Sorry if that was not implied from the question, its telling me I need LuaTex)? – soandos Dec 3 '13 at 6:57
• @soandos I believe the new graphs library requires luatex. It's still LaTeX, but you have to compile with lualatex rather than pdflatex. – Torbjørn T. Dec 3 '13 at 7:03
• @TorbjørnT. the rest of it seems to work fine without luatex. Is there a source for that? Additionally, compiling with lualatex gives me an error on \usegdlibrary{trees} – soandos Dec 3 '13 at 7:37
• @soandos Sorry, I was a bit wrong, it's the graphdrawing library that requires LuaTeX. See the manual for the CVS version (ch. 27, Using Graph Drawing in TikZ). – Torbjørn T. Dec 3 '13 at 7:42
• @TorbjørnT. got it. This may be a silly question, but how much of the rest of my document do I have to change because of this? Also, how can I turn my document into a pdf? NOTE: Even compiling as luaLatex, it can't deal with \usegdlibrary – soandos Dec 3 '13 at 7:52
\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\node {a}
child{node {b}}
child{node {c}};
\end{tikzpicture}

\begin{tikzpicture}[->]
\node {a}
child{node {b}}
child{node {c}};
\end{tikzpicture}

\begin{tikzpicture}[->,sibling distance=15em]
\node {a}
child{node {b}}
child{node {c}};
\end{tikzpicture}
\end{document}

A bit complicated when handling many children but i guess this is what you wanted. There are many style options for the distance between the children and the layout can be set with defining a style.

• Please read the note. I wanted to do this specifically with automatic node positioning. – soandos Dec 3 '13 at 14:17