How to draw syntactical trees with parallel leaves for a natural language?
This is not commonly the way trees are represented in the linguistic literature, so none of the regular tree drawing packages (qtree
and tikz-qtree
) do this by default.
Specifically, the way trees are drawn in the linguistics literature, the terminal nodes are not drawn at the same level (i.e. with the words along a baseline and the tree growing up from there.) So to take a simple tree of e.g John thinks he loves Mary, we could use the tikz-qtree
to draw the tree easily:
\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}
\Tree [.S [.NP John ]
[.VP [.V\0 thinks ]
[.S [.NP he ]
[.VP [.V\0 loves ] [.NP Mary ]]]]]
\end{document}
Notice that the terminal nodes of the tree don't line up with the other terminal nodes along a baseline. This is normal in the linguistics literature, although often when teaching students how to draw trees by hand we start with all the words lined up at the bottom (i.e. at the same level as the lowest word in the tree.)
A new solution using tikz-qtree
Starting from version 1.2 of tikz-qtree
there is now a simple way to have terminal nodes line up, although choosing the value requires some manual calculation. The frontier
key allows you to specify the placement of terminal nodes using the distance from root
parameter. So in the example above we can make distance from root
equal to 5cm and the terminal nodes will line up. This value would need to be changed for each individual tree.
\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}
\begin{tikzpicture}[frontier/.style={distance from root=5cm}]
\Tree [.S [.NP John ]
[.VP [.V\0 thinks ]
[.S [.NP he ]
[.VP [.V\0 loves ] [.NP Mary ]]]]]
\end{tikzpicture}
\end{document}
Another simple solution
As an alternative to the frontier
key solution above, kgr's very simple answer using regular TikZ methods can also be applied using tikz-qtree
. All that is needed is to insert extra brackets in the tree to make dummy nodes. So you can simply do the following:
\begin{tikzpicture}
\Tree [.S [.NP [[[ John ]]] ]
[.VP [.V\0 [[ thinks ]] ]
[.S [.NP [ he ] ]
[.VP [.V\0 loves ] [.NP Mary ]]]]]
\end{tikzpicture}
The only difference between the tree above and this tree is that the terminals have been enclosed in extra brackets: three for John, two for thinks and one for he. For the occasional tree this might be a simple way to achieve what you want.
An old solution using xyling
The xyling
package also has a way to do this, although its input method for tree drawing is much more cumbersome. Here's the same tree formatted using xyling
: (I've left this part of the answer in for posterity; the tikz-qtree
answers are really much simpler.)
% compile with latex + dvips
\documentclass{article}
\usepackage{xyling}
\begin{document}
\Tree{ & \K{S}\B{dl}\B{dr}\\
\K{NP}\B{d} & & \K{VP}\B{dl}\B{dr}\\
\B[6]{d} & \K{V}\B{d} & & \K{S}\B{dl}\B{dr}\\
\B[6]{d} & \B[6]{d}& \K{NP}\B{d} & & \K{VP}\B{dl}\B{dr}\\
\B[6]{d} & \B[6]{d}&\B[6]{d} & \K{V}\B{d} & & \K{NP}\B{d}\\
John & thinks & he & loves & & Mary }
\end{document}
Basically, xyling
sets a kind of tabular grid to draw trees. This allows you to put all the terminal nodes in the lowest row of the grid and then add explicit branches in the empty cells above it up to its non-terminal node. Since the default branch drawing command assumes a node label you need to use the optional argument of the \B
command to raise the starting points of the extra branches. A value of 6
seems to do an adequate job.
xyling
uses Postscript specials and will not work out of the box with pdflatex
, so you need to compile this file with latex+dvips+ps2pdf
The documentation explains how to modify the style file to change this (why it's not a package option I don't know.) In fact, given that there is now pdf support for much of the xy
package upon which xy-ling
is based, it would be simple to modify the style file to use either pdflatex
or latex+dvips
.
I would advice to use the TikZ package. Have a look in the documentation , pp. 475 for "normal trees", and pp. 386, for "mindmap-like trees".
For completeness, the extremely powerful forest
package should be included ;):
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage[linguistics]{forest}
\newcommand*\primary{\textsuperscript{0}}
\begin{document}
\begin{forest}
for tree={
where n children=0{tier=terminal}{},
}
[S
[NP
[John
]
]
[VP
[V\primary
[thinks
]
]
[S
[NP
[he
]
]
[VP
[V\primary
[loves
]
]
[NP
[Mary
]
]
]
]
]
]
\end{forest}
\end{document}
tier
is doing the work of keeping the final nodes aligned. where n children=0{}{}
is applying this to the terminal nodes (which have no children).
If you have only an earlier version of Forest (prior to v.2) and cannot update, you will need this code instead:
\documentclass[standalone, border=5pt]{standalone}
\usepackage{forest}
\newcommand*\primary{\textsuperscript{0}}
\begin{document}
\begin{forest}
for tree={
where n children=0{tier=terminal}{},
parent anchor=south,
child anchor=north,
}
[S
[NP
[John
]
]
[VP
[V\primary
[thinks
]
]
[S
[NP
[he
]
]
[VP
[V\primary
[loves
]
]
[NP
[Mary
]
]
]
]
]
]
\end{forest}
\end{document}