4

I'm new to tikz-qtree, and can't find an automatic way to do something that qtree did very nicely. With qtree, if you don't have a label for a single intermediate node, you get a straight line from the grandmother to the granddaughter. With tikz-qtree, you get a "kink". Compare the following:

With qtree:

\documentclass{article}
\usepackage{qtree}

\begin{document}

\Tree [ Wiiiiiiiiiide [ nar- -row ] ]

\Tree [ nrw [ wiiiiiiiiiiiii- -iiiiiiiiiiiide ] ]

\end{document}

With tikz-qtree

\documentclass{article}
\usepackage{tikz,tikz-qtree}

\begin{document}

\Tree [ Wiiiiiiiiiide [ nar- -row ] ]

\Tree [ nrw [ wiiiiiiiiiiiii- -iiiiiiiiiiiide ] ]

\end{document}

Is there any way to get the nice straight line in tikz-qtree, or do I have to adjust it manually? Thanks in advance.

3

There's no really nice way to deal with empty nodes on the spine of the tree with tikz-qtree because it uses a very different method for drawing the trees. You can accommodate for the width problem by setting the text width of the leaf nodes to a constant based on your longest node (or some fixed value if you prefer.)

An alternative is to use the forest package, which has some very nice features as well. I've added the forest version of the tree to the example for comparison. Neither is perfect, but this is due to the fact that they both are designed to make nicer trees overall, and the empty nodes problem is an unfortunate side-effect.

\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\usepackage{calc}
\newlength{\tmplen}
\settowidth{\tmplen}{Wiiiiiiiiiide}
\tikzset{every leaf node/.style={
    text width=\tmplen},
    every node/.style={parent anchor=center, child anchor=north,text depth=4ex}}
\usepackage{forest}
\forestset{nice empty nodes/.style={
for tree={calign=fixed edge angles},
delay={where content={}{shape=coordinate,for parent={for children={child anchor=north}}}{}} }}

\begin{document}
\texttt{tikz-qtree}

\Tree [ Wiiiiiiiiiide [ nar- -row ] ]
\Tree [ nrw [ wiiiiiiiiiiiii- -iiiiiiiiiiiide ] ]

\texttt{forest}

\begin{forest}
[,nice empty nodes [Wiiiiiiiiiide] [ [nar-] [-row] ] ]
\end{forest}
\begin{forest}
[,nice empty nodes [nrw] [ [wiiiiiiiiiiiii-] [-iiiiiiiiiiiide] ] ]
\end{forest}
\end{document}

output of code

  • child anchor=north is probably better than anchor=north. – cfr Aug 12 '15 at 1:23
  • Thanks Alan. forest.sty was new to me but it's working beautifully. – rtruswell Aug 12 '15 at 18:56
  • @rtruswell If you find the answer useful, it's helpful to click on the tick beside. (Not obligatory, but tells other users that an answer solved the problem posed in the question.) On forest be aware that it needs some tweaking to get trees that aren't too compact sometimes. See Making a certain tree style the default for forest for how to make a default style, which will help a lot. – Alan Munn Aug 12 '15 at 18:59
  • child anchor=parent is probably better than child anchor=north, although possibly not in a linguistics context. – cfr Dec 16 '17 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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