# How to balance binary branches and repair shorthand triangles in LFG style c-trees using tikz-qtree

I have modified the example from the tikz-qtree documentation to form this LFG style c-tree, but am having difficulty balancing the binary branches in general, and the IP branches and roof/triangle DP 'the cat' in particular.

My question is how to control the vertical distance between each mother and daughter node so that branches can be made reasonably parallel to each other when comparing level to level? And how to fix the upside-down shorthand DP triangle, and also shorten the width of both triangles to better match the text width? Would very much appreciate suggestions.

\documentclass[12pt]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\begin{document}
\tikzset{level 1/.style={level distance=10pt,sibling distance=10pt}}
\tikzset{level 2/.style={level distance=20pt,sibling distance=10pt}}
\tikzset{level 3/.style={level distance=40pt,sibling distance=15pt}}

\begin{tikzpicture}[level 1,level 2,level 3]
\tikzset{every tree node/.style={align=center,anchor=north}}
\tikzset{inner ysep=3pt,outer ysep=0pt}
\Tree%
[. {IP} [.\node{Spec=|\\Subj=|\\[-2pt]DP}; \edge[roof]; {the cat} ]
[.\node{U=D\\VP}; \node{U=D\\V\0\\[-4pt]sat};
[.\node{Pcase=|\\PP}; [.\node{U=D\\P\0\\[-5pt]on}; ]
[.\node{Obj=|\\DP}; \edge[roof]; {the mat} ] ] ]
]%
\end{tikzpicture}
\end{document}


@Alan Munn: Yes, exactly. I would prefer to have the DP of 'the cat' lined up horizontally with the VP just as you say. In general what I would like to do is to make the left branch from IP to DP shorter but parallel with the other leftwards branches: that is, parallel to VP to V-zero and PP to P-zero leftwards branch and ditto with all the rightwards branches.

I guess my question is: how do you shorten or lengthen each single branch of the c-tree from each mother node to each daughter node?

The code [inner xsep=0pt] etc. works well in reducing the width of the bottom line of the triangle: thank you for that. But the DP triangle 'the cat' is still upside down. Unfortunately I am not allowed to upload a jpg to this site of the c-tree as MikTeX produces it on my computer. It appears that having multiple levels of lines in each node in the style of LFG syntactic theory plays havoc with the binary branches.

-
When you add three styles like that, the last will overwrite the two first, so it is the level distance and sibling distance from the level 3 style that is used for the entire tree. As it is, this doesn't provide enough space for the DP triangle to grow upward. Increase the level distance of level 3 to 50pt or 60pt and the triangle looks better. I don't know if/how it's possible to specify different level distances within a tree. –  Torbjørn T. Dec 8 '11 at 9:08
Ah, sorry, I see now in the TikZ manual that when making trees with TikZ, you can access the different levels such as you have done. Perhaps tikz-qtree uses a different mechanism for drawing the trees, as this doesn't work in your case. –  Torbjørn T. Dec 8 '11 at 9:12
I'm not sure I understand what you want to change with respect to the tree. What do you mean by making the branches parallel? Do you want to make the length of the left branch of IP shorter so that the DP node is horizontally aligned with the VP node? Also, I don't get an upside down triangle with your example. –  Alan Munn Dec 8 '11 at 14:47

This is not a very simple problem to solve, since most automatic tree drawing packages assume that internal nodes are the same height, but in your case, you have internal nodes of different heights. However, with tikz it is possible to do many magical things.

Dealing with uneven node sizes

The basic idea is the following: for nodes that are large, we adjust the text height manually so that the actual text height isn't used to determine the size of the node. This has the effect of moving the node up. This is how the alignment between the two uneven sized nodes is achieved.

Once having moved the node text, we need to shorten the branch of the tree that leads to that node; we do this using the [shorten] option of the \edge command. The syntax of the shorten parameter is:

shorten >=length


where > means shorten the end of the line (< would shorten the beginning).

Modifying the roof size

The roof node style simply creates a path relative to the parent node and the child node. By default nodes have an inner and outer sep. So you can reduce the size of the triangle by specifying a 0pt inner xsep for the node under the roof. (You can also specify inner sep=0pt which will reduce the ysep value too, but this makes the text too close to the bottom of the roof.)

Some other modifications

• Rather than manually inserting negative \\[] commands in the terminal nodes, I've created a new command \word which raises a terminal node by 3pt; you can specify a different value with its optional argument.

• It's not necessary to make every node in the tree a TikZ \node; it's simpler to use explicit TiKZ nodes only if:

1. you need to modify properties of the node (e.g. setting the inner sep or putting a box around it)
2. you need to label the node so that you can draw an arrow to or from it

Code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz-qtree,tikz-qtree-compat}
\newcommand{\word}[2][3pt]{\raisebox{#1}{#2}}
\begin{document}
\tikzset{level 1/.style={level distance=10pt,sibling distance=10pt}}
\tikzset{level 2/.style={level distance=20pt,sibling distance=10pt}}
\tikzset{level 3/.style={level distance=40pt,sibling distance=10pt}}

\begin{tikzpicture}[level 1,level 2,level 3]
\tikzset{every tree node/.style={align=center,anchor=north}}

\Tree%
[.IP
\edge[shorten >=14pt];   [.\node[text height=2em]{Spec=|\\Subj=|\\DP};
\edge[roof]; \node[inner xsep=0pt] {the cat}; ]
[.{U=D\\VP} [.{U=D\\V\0\\\word{sat}} ]
[.{Pcase=|\\PP} [.{U=D\\P\0\\\word{on}} ]
[.{Obj=|\\DP} \edge[roof]; \node[inner xsep=0pt] {the mat}; ]]]]
\end{tikzpicture}
\end{document}


-

@Alan Munn: Yes, exactly. I would prefer to have the DP of 'the cat' lined up horizontally with the VP just as you say. In general what I would like to do is to make the left branch from IP to DP shorter but parallel with the other leftwards branches: that is, parallel to VP to V-zero and PP to P-zero leftwards branch and ditto with all the rightwards branches. I guess my question is: how do you shorten or lengthen each single branch of the c-tree from each mother node to each daughter node?

The code [inner xsep=0pt] etc. works well in reducing the width of the bottom line of the triangle: thank you for that. But the DP triangle 'the cat' is still upside down. Unfortunately I am not allowed to upload a jpg to this site of the c-tree as MikTeX produces it on my computer. It appears that having multiple levels of lines in each node in the style of LFG syntactic theory plays havoc with the binary branches.