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 need to draw a tree, and constantly using dotty and including the PNGs is starting to be a pain. Is there a way to get LaTeX to draw it's own trees that doesn't involve learning an entirely new language like TikZ?

share|improve this question
Tikz isn't really an entirely new language. I'd recommend it for you. –  Will Robertson Nov 16 '10 at 1:23

1 Answer 1

up vote 59 down vote accepted

While I'd normally second Will Robertson's comment, since TikZ is fantastic and worth learning, I think TikZ's overkill for this situation. I personally find its tree specification syntax bulkier than necessary. My preferred tool for the job is the qtree package (which is on CTAN, too, and is apparently included in both TeX Live and MikTeX). The package is really simple to use. Consider the following TeX:

\Tree[.IP [.NP [.Det \textit{the} ]
               [.N\1 [.N \textit{package} ]]]
          [.I\1 [.I \textsc{3sg.Pres} ]
                [.VP [.V\1 [.V \textit{is} ]
                           [.AP [.Deg \textit{really} ]
                                [.A\1 [.A \textit{simple} ]
                                      \qroof{\textit{to use}}.CP ]]]]]]

This produces the following tree:

Sample X-bar theory parse tree.

That's all it takes! And what's great about it is that the TeX description reads like the tree. I can glance at the TeX, and I instantly know what the created tree is going to look like. The basic syntax is simply [.node-name subtrees... ]; \qroof, which draws the triangle, requires its node name at the end, instead. The \1 is just a shortcut for a math-mode prime. In addition, qtree will always render _ and ^ as sub- and super-scripts, too. (Unless you turn this off.)

In general, you can provide node names at the beginning ([.+ 1 [.* 2 3 ]]) or the end ([ 1 [ 2 3 ].* ].+); you can even provide node names in both places, but then they must match (unsurprisingly). This, incidentally, is why \qroof takes its node name the way it does. You can even leave the node name off entirely to get a node with a smooth join. If any of this is unclear, check out the manual.

Now, qtree as-is has one downside, which is that it is designed for simple trees. It does offer limited support for changing inter-node spacing, framing parts of trees, and things like that, but it's not capable of doing anything incredibly fancy. But luckily, if you want that, you can still get it: enter tikz-qtree. This package allows you to leverage the full power of TikZ to draw your trees. The two obvious features are: (a) instead of text, the labels in a tree can be arbitrary \nodes; and (b) you can redefine how it draws the edges to get arrows, dashed lines, curving edges, and so on. But it's more powerful than just this: if you embed a \Tree into a TikZ picture, you can do whatever you want with the nodes, such as circle them, draw arrows between them for a transformation, etc.

Maybe you don't need this power now, but the take-home message is that using qtree won't lock you in to the simple trees. If you decide that you want the more powerful trees, all you need to do is change one import; everything will keep working the way it did, but you get more power, too. I'm not sure if tikz-qtree this actually uses qtree under the hood or not, but either way, all the syntax for qtree still works, and the output is identical, at least as far as I can tell.

(PS: Linguists, please excuse/correct any errors in the above tree; it's been a year or two since my syntax course.)

share|improve this answer
Great answer! I wasn't aware of this package and the facility to later move to tikz if necessary makes this perfect for the OP. –  Will Robertson Nov 16 '10 at 2:27
That is really awesome! Didn't know that existed at all! –  Edd Nov 16 '10 at 12:17
What are the periods for after the brackets? –  Billy ONeal Nov 17 '10 at 3:15
@Billy: They "just are." It's part of the syntax of qtree, as I tried to make clear. I imagine it's so that [.a b c] and [a b c] yield different trees; the former has a root node a with children b and c, the latter has an empty root node with children a, b, and c. Follow the links for pictures of what each produces. –  Antal S-Z Nov 17 '10 at 8:19
tikz-qtree doesn't use qtree underlyingly; it's a completely new implementation. The syntax of the input is the same, however. There is also a compatibility package tikz-qtree-compat which makes converting from older qtree source into tikz-qtree a bit easier. –  Alan Munn Jan 2 '11 at 21:12

Your Answer


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.