# File explorer-like tree using TiKZ/graphs

I want to draw a binary tree using TiKZ (more exactly a rooted binary DAG, but there is only one occurence of node with two parents). I managed to obtain a tree using the standard TiKZ graph layouts:

Here is the corresponding code (to compile with LuaTeX):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
\begin{scope}%
[every node/.style={draw,circle}]
\graph [fresh nodes, math nodes] {
b -> {
c ->{
b -> {
"\Lambda", "\emptyset"
},
"\emptyset"
},
a -> {
b -> {
a -> {
"\Lambda", "\emptyset"
},
a -> {
M0/a -> {
"\Lambda",
c -> {
"\Lambda", "\emptyset"
}
},
"\emptyset"
}
},
c -> {
a -> {
(M0),
"\emptyset"
},
"\emptyset"
}
}
}
};
\end{scope}
\end{tikzpicture}
\end{document}


however the tree would be more legible if the "left" child of a node is placed under its parent (with the exception of the node pointing to another part of the graph), and the "right" child of a node is placed on its right. Note that this behavior is reversed in my tentative…

Is there some way to parameterize graphs to obtain this?

• Have a look here. Not an answer to your question but maybe a source for inspiration... – vaettchen Jan 9 '16 at 16:36
• So you have the code for the image you show? Please add that to the question as well, it's much easier for people to see what to change if they know what the starting point is. – Torbjørn T. Jan 9 '16 at 16:46
• Could you turn it into a complete example (a minimal working example), so that we can copy-paste the code and compile it directly? It can sometimes be a pain figuring out which libraries are required, for example. – Torbjørn T. Jan 10 '16 at 8:28
• I converted to a full example. Thank you for your interest. – scand1sk Jan 10 '16 at 9:09

Not entirely satisfactory, but I could obtain the layout I wanted by relying on manual positioning. Here is the result. I am still interested in a more "clever" solution.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees,positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}%
[every node/.style={draw,circle},inner sep=.1em]
\graph [Cartesian placement,fresh nodes, math nodes, grow right=.8] {
rb/b -> [dashed] ra/a [x=.8] -> [dashed] rc/c [x=3.2] -> [dashed] "\emptyset" [x=3.2];
(rb) -> cb/c ->[dashed] "\emptyset";
(cb) -> b -> [dashed]  "\emptyset";
(b) -> l0/"\Lambda" [x=2] ;
(ra) -> ba/b [x=1.6,y=3] ->[dashed] aaac/a [x=2.4,y=3,fill=lightgray] ->[dashed] "\emptyset" [x=2.4,y=3];

(ba) -> a [x=1.6,y=3] ->[dashed] "\emptyset" [x=1.6,y=3];
(a) -> (l0);

(aaac) -> auc/a [x=3.2,y=4] ->[dashed] c [x=3.2,y=4] ->[dashed] "\emptyset" [x=3.2,y=4];

(auc) -> (l0) ;
(c) -> (l0);

(rc) -> aaac2/a [x=4.8,y=6,fill=lightgray] ->[dashed] "\emptyset" [x=4.8,y=6];

(aaac2) -> [out=-90,in=90] (auc);
};
\end{scope}
\end{tikzpicture}
\end{document}%