# Position a tikz tree based on interior node

How can I position a tikz tree based on an interior node, i.e. instead of defining the position of the root, defining the position of an interior node?

For example, consider the following code.

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node {a}
child {node at (1,0) {b}
child {node {c}}
};

\node {x}
child {node at (3,0) {y}
child {node {z}}
};
\end{tikzpicture}
\end{document}


This code does not produce the desired output, but it shows what I imagine.

Desired would be two trees where b and y are at (1,0) and (3,0), respectively, and the rest of the trees is normal around them, e.g., a is above b and c is below b respecting the level distance, etc.

Especially if a and c become larger trees, aligning the two trees at the inner node becomes tedious shifting work.

– cfr
Jan 11, 2017 at 23:24

In order to prevent the nodes being placed as they are defined, you can use TikZ's graph drawing facilities with the trees layout library.

For example,

\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph [tree layout]
{
a -- { b[at={(1,0)}] , c }
};
\graph [tree layout]
{
x -- { y[at={(3,0)}] , z }
};
\end{tikzpicture}
\end{document}


Compiling with LuaTeX gives the following result.

You can stick to the more verbose syntax if you prefer and still use the algorithmic graph-drawing facilities. This is just more concise.

• Too sad that there seems to be no solution for plain pdflatex. However, this works nicely in lualatex, so thank you! Feb 1, 2017 at 8:02
• You could set the baseline to a particular node with Forest or, for a tikzpicture in the environment options. But that is for the whole picture. Probably Forest could do it with pdflatex. Well, definitely, but you need to fake a root in that case.
– cfr
Feb 2, 2017 at 2:20