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 want to create syntactic trees and align them in LaTeX as in the picture below.

enter image description here

Can you help me?

share|improve this question
    
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. –  macmadness86 Apr 28 '13 at 16:38
    
@macmadness86 although it's likely that your answer will be the only one in this case, it's usually considered polite to wait some time before reminding people about accepting your answer. There's a fine line between informing new users about how the site works and badgering them to accept your answer. Also, tags are for questions, not answers, so while the linguistics tag is entirely appropriate, the tikz-qtree tag is really based on your answer and not the question; there are other viable ways to create trees in LaTeX. –  Alan Munn Apr 28 '13 at 18:57
    
@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! –  macmadness86 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

1 Answer 1

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}; ] ]
        [.{ADVP}
            [.{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

sample output updated to match code

If you are looking for more information, check out Alan Munn's informative answer here.

share|improve this answer

Your Answer

 
discard

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.