# How to create syntactic trees and align them in LaTeX?

I want to create syntactic trees and align them in LaTeX as in the picture below.

Can you help me?

• The tikz-qtree package gives an example similar to this in its documentation. Try that and come back with a sample document if you're having problems. There are also lots of tikz-qtree questions on the site. – Alan Munn Apr 28 '13 at 16:01
• I would recommend that you tag this question with linguistics, because it is a linguistics-related question; and tikz because it deals with graphics. This will grab more attention to your question. – Jonathan Komar Apr 28 '13 at 16:38
• @Alan Munn, duly noted! I only said that in this case because he wrote a comment (which has since been deleted because it was inappropriate-a typical new-user thank you very much comment-) which made it seem like my answer had solved his question. As he is a very new user, I wanted to ensure that he checks the mark without just ignoring it like many new users. You are right about the tikz-qtree tag. I wasn't sure if I should include that tag. I will keep that in mind for next time. I will also delete my comment. I want to show good manners! – Jonathan Komar Apr 28 '13 at 21:01
• @justlife Since macmadness has definitely provided an answer to your question, it would now be helpful to click on the green checkmark beside it to "accept" the answer. – Alan Munn Apr 29 '13 at 17:53

You will need

• tikz package
• tikz-qtree package

This code will get you pretty near what you are trying to achieve:

\documentclass[]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usepackage{tikz-qtree}
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
\newcommand{\subscript}[1]{\ensuremath{_{\textrm{#1}}}}
\begin{document}

\tikzset{level 1/.style={level distance=20pt}}
\tikzset{level 2/.style={level distance=30pt}}
\tikzset{level 3+/.style={level distance=20pt}}
\tikzset{frontier/.style={distance from root=10\baselineskip}}
\begin{tikzpicture}[remember picture]
\Tree
[.{ST}
[.{NP}
[.NNP \node[](john){John}; ]
[.NNP \node[](smith){Smith}; ] ]%done
[.{VP} % level 2 VP contains VP1 CC VP2
[.{VP\subscript{1}}
[.{VBD} \node[](walked){walked}; ]
[.{NP}
[.{PRP\$} \node[](his){his}; ] [.{NN} \node[](dog){dog}; ] ] ] [.{CC} \node[](and){and}; ] [.{VP\subscript{2}} [.ADVP [.{RB} \node[] (afterwards) {afterwards}; ] ] [.{VBD} \node[] (met) {Met}; ] [.{NP} [.{NNP} \node[] (mary) {Mary}; ] ] ] ] [.{.} [[[\node[](dot){.}; ] ] ] ] ] ] \begin{scope}[yshift=-9.5cm,xshift=-3cm,grow'=up] \Tree [.{ST} [.{NP} [.{NNP} \node[] (john2) {John}; ] [.{NNP} \node[] (smith2) {Smith}; ]] [.{VP} [.{VBD} \node[] (walked2) {walked}; ] [.{NP} [.{PRP\$} \node[] (his2) {his}; ]
[.{NN} \node[] (dog2) {dog}; ] ]]
[.{.}
[[[[\node[] (dot2){.}; ]]]] ] ]
\end{scope}

\begin{scope}[yshift=-9.5cm,xshift=3cm,grow'=up]
\Tree
[.{ST}
[.{NP}
[.{PRP} \node[] (he2) {He}; ] ]
[.{VP}
[.{VBD} \node[] (met2) {met}; ]
[.{NP}
[.{NNP} \node[] (mary2) {Mary}; ] ]
[.{RB} \node[] (later2) {later}; ] ] ]
[.{.}
[[[[{.} ]]]] ] ]
\end{scope}
%draw the lines
\begin{scope}[remember picture, overlay]
\draw[black,dotted,thick](john)     to (john2);
\draw[black,dotted,thick] (smith)   to (smith2);
\draw[black,dotted,thick] (walked)to (walked2);
\draw[black,dotted,thick] (his)     to (his2);
\draw[black,dotted,thick] (dog)     to (dog2);
\draw[black,dotted,thick] (dot)     to [out=220,in=50] (dot2);
\draw[black,dotted,thick] (met)     to (met2);
\draw[black,dotted,thick] (mary)  to (mary2);
\end{scope}
\end{tikzpicture}

\end{document}

\end{document}


I will post updated code once I get the leaf nodes aligned! I am not sure why the . leaf is not being aligned with the rest of the leaves.

UPDATE The solution to the problem of getting the . leaf nodes aligned with the other leaves is to nest it within brackets [[[]]], which puts it on a deeper level.

Sample Output