I am trying to draw a refutation tree:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree
[.\node[label= {$\langle \texttt{stateA(X)}, 0 \rangle$}] {};
[.\node[label= {$\langle \texttt{stateB(X, Y)}, 0 \rangle$}] {};
\edge node[left] {$X=a, Y=b$}; [.\node[label={$\langle \texttt{stateC(a,b)}, 0 \rangle$}] {};
\node[ label=below: {$\langle [], res1 \rangle$}] {};
]
\edge node[right] {$X=a, Y=c$}; [.\node[label={$\langle \texttt{stateD(b, c)}, 0 \rangle$}] {};
\node[ label=below: {$\langle [], res2 \rangle$}] {};
] ] ]
\end{tikzpicture}
\end{document}
Hovewer, in the resulting tree most labels are not in the right place. How can I possibly fix this?
Initially, I was experimenting with style definitions from this example but circles or rectangles do not seem to be a fit.
Best Answer
A few comments about your tree.
It's generally never necessary to use explicit
\node
commands withtikz-qtree
since each[.label ]
constituent label is automatically a node.To label an edge of a tree, you should use the
[auto=left]
and[auto=right]
parameters for the node. This will ensure better placement of the label text.When making complicated node labels, your tree will be much more readable if you create some sensible markup for the different components of it.
Here's a version of your tree taking all these ideas into account:
I've created a
\brk
command to wrap something in angle brackets. I've also created a\state
command that puts its argument in\texttt
. This way if you decide to change that formatting decision down the line you only need to change one command.