Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
I think you place what should be the node contain within a label. Try to replace \node[label= {$\langle \texttt{stateA(X)}, 0 \rangle$}] {}; with \node {$\langle \texttt{stateA(X)}, 0 \rangle$}; and similar replacements for the rest of your tree. –  Ignasi Feb 27 '12 at 12:14
    
Thanks, it is much better this way! Edge labels still looked out of place, so I had to quick-fix this \edge node[left] {$X=a, Y=b$}; with this \edge node[left] {\small{$X=a$; ~ $Y=b$} ~~~~~~~~~~}; (ugly but still working...) –  sdk Feb 27 '12 at 13:08
    
I have also added spacing parameters: \begin{tikzpicture}[sibling distance=25mm, level distance=40pt] Seems to be solved! –  sdk Feb 27 '12 at 13:18

1 Answer 1

up vote 4 down vote accepted

A few comments about your tree.

  • It's generally never necessary to use explicit \node commands with tikz-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.

\documentclass{article} 

\usepackage{tikz} 
\usepackage{tikz-qtree} 
\newcommand\state[1]{\texttt{#1}}
\newcommand\brk[1]{$\langle #1 \rangle$}
\begin{document} 

\begin{tikzpicture}[level distance=40pt,sibling distance=25mm] 
  \Tree  
     [.{\brk{ \state{stateA(X)}, 0 }}   
        [.{\brk{ \state{stateB(X, Y)}, 0 }}  
            \edge node[auto=right] {$X=a, Y=b$}; 
            [.{\brk{ \state{stateC(a,b)}, 0 }}   
                 [.{\brk{ [], res1 }} ]  
                 ]  
            \edge node[auto=left] {$X=a, Y=c$}; [.{\brk{ \state{stateD(b, c)}, 0 }}  
                 [.{\brk{ [], res2 }} ]  
                  ]   ]   ] 
\end{tikzpicture} 
\end{document} 

output of code

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.