You can use two trees sitting on top of each other.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=2.5cm]
\node (topnode) at (0,5) { {\{\{1\}\{2\}\}\{3\}\{4\}}\} }
child { node {{\{\{1,2\}\{3\}\{4\}}\}} }
child { node {{\{\{1,3\}\{2\}\{4\}}\}} }
child { node {{\{\{1,4\}\{2\}\{3\}}\}} }
child { node {{\{\{2,3\}\{1\}\{4\}}\}} }
child { node {{\{\{2,4\}\{1\}\{3\}}\}} }
child { node {{\{\{3,4\}\{1\}\{2\}}\}} }
;
\node[minimum width=3cm](bottomnode) {\{\{1,2,3,4\}\}} [grow'=up]
child { node {{\{\{1,2,3\}\{4\}}\}} }
child { node {{\{\{1,2,4\}\{3\}}\}} }
child { node {{\{\{1,2\}\{3,4\}}\}} }
child { node {{\{\{1,3,4\}\{2\}}\}} }
child { node {{\{\{1,3\}\{2,4\}}\}} }
child { node {{\{\{1,4\}\{2,3\}}\}} }
child { node {{\{\{2,3,4\}\{1\}}\}} }
;
\foreach \x in {1,2,3}{
\draw (topnode-1) -- (bottomnode-\x);
}
\end{tikzpicture}
\end{document}
![enter image description here](https://i.stack.imgur.com/dRDCT.png)
I'll leave the connection lines to you if you don't mind. You can access each node by first writing up the parent node name followed by a dash and the item number e.g. (topnode-5)
.
If you are using graph syntax, directed edges are specified within the tree specification itself. For example,
{ r -> a }
indicates a directed edge from r
to a
.
The whole point of the graph drawing libraries is that you specify the relationships and let Lua figure out the detailed structure.
Using this syntax, the directed edges are no problem. And, thanks to Gonzalo Medina's comment, I'm now able to get mathematical content into the nodes as well.
So, for example, using the graph syntax, I can produce
![graph](https://i.stack.imgur.com/C7QI3.png)
using this specification:
% modified from Gonzalo Medina's comment (below)
\tikz [tree layout] \graph [math nodes, nodes={draw, circle, minimum size = .5cm}, sibling sep=0pt]
{aaaa [as=$\land$] -> {aa [as=$\lnot$] -> a , aaa [as=$\rightarrow$] -> {b , c}} };
If your graphs are all trees i.e. have a single root, you might like to use a specialised tree-drawing package such as forest
, qtree
or tikz-qtree
instead. If they are not all trees, you can still do this but only by tricking the package into thinking you are really drawing a tree, so it gets more complicated.
For your tree, for example, the forest
specification looks like this:
\begin{forest}
for tree={
edge = {->},
circle,
minimum size=5mm,
inner sep=0pt,
draw,
math content,
tier/.wrap pgfmath arg={tier #1}{level()},
anchor=center
},
[\land
[\lnot
[a]
]
[\rightarrow
[b]
[c]
]
]
\end{forest}
![tree](https://i.stack.imgur.com/gH3Je.png)
Here including maths in the nodes is a bit more straightforward, but obviously you have to specify the precise structure of the tree you want - you can't just specify the relationships as you can with the graph drawing libraries.
Complete Code
\documentclass[tikz,multi,border=10pt]{standalone}
\usetikzlibrary{arrows.meta,graphs,graphdrawing}
\usegdlibrary{trees}
\usepackage{forest}
\tikzset{
>=Stealth[], % does work
}
\begin{document}
% modified from 406 of manual, and using Gonzalo Medina's comment (below)
\tikz [tree layout] \graph [math nodes, nodes={draw, circle, minimum size = .5cm}, sibling sep=0pt]
{aaaa [as=$\land$] -> {aa [as=$\lnot$] -> a , aaa [as=$\rightarrow$] -> {b , c}} };
\begin{forest}
for tree={
edge = {->},
circle,
minimum size=5mm,
inner sep=0pt,
draw,
math content,
tier/.wrap pgfmath arg={tier #1}{level()},
anchor=center
},
[\land
[\lnot
[a]
]
[\rightarrow
[b]
[c]
]
]
\end{forest}
\end{document}
EDIT
If you prefer to stick to the old syntax for trees, you can do that so long as you don't mix it in problematic ways with the graph drawing environment.
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{
my tree/.style={
->,
nodes={draw, circle, minimum size = .5cm},
>=Stealth[],
},
}
\begin{document}
\tikz [ my tree ]
\node {$\land$}
child {
node {$\lnot$}
child {
node {$a$}
}
}
child {
node {$\rightarrow$}
child {
node {$b$}
}
child {
node {$c$}
}
};
\end{document}
I don't get the problems with overlapping nodes shown in your screenshot provided I do not load the graphdrawing
TikZ library:
![old tree syntax](https://i.stack.imgur.com/C1ySc.png)
Best Answer
Maybe not as nice looking a tree, but a lot faster to input. The
tikz-qtree
package is designed to optimize the spacing between nodes.