1

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.east)
-- +(8pt,0)
|- (\tikzchildnode)}}}
\begin{document}

\begin{tikzpicture}
\tikzset{grow'=right,level distance=32pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ] [.N mat ] ] ] ] ]
\end{tikzpicture}

\end{document}
3

You could use forest. But if you want to draw trees a lot, you have to sit down and learn how to use the package of your choice - be it tikz-qtree, qtree, forest or whatever. Since you don't say what is difficult, it is hard to say anything more helpful.

\documentclass[border=5pt,tikz]{standalone}
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}
\begin{forest}% initial code from Gonzalo Medina's answer at http://tex.stackexchange.com/a/56909/
  for tree={
    edge path={
      \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    grow'=0,
    parent anchor=east,
    child anchor=west,
    align=left,
    base=b,
    where n children=0{
      calign with current,
    }{},
    tier/.wrap pgfmath arg={tier=tier #1}{level()}
  }
  [S, name=first
    [NP, name=second
      [Det, name=top, name=third
        [the, name=fourth]
      ]
      [N
        [cat]
      ]
    ]
      [VP
        [V
          [sat]
        ]
        [PP
          [P
            [on, name=fifth]
          ]
          [NP
            [Det
              [the]
            ]
            [N
              [mat, name=sixth]
            ]
          ]
        ]
      ]
    ]
    \coordinate [above=5pt of top.north] (above);
    \foreach \i in {first, second, third, fourth, fifth, sixth}
    \node [font=\scshape\scriptsize] at (above -| \i) {\i};
\end{forest}

\end{document}

cats on mats

  • Thank you very much. I tried. My system says "the forest.sty not found"!!!! – Yuming Feng Jan 23 '15 at 0:32
  • @YumingFeng Then you have an incomplete (or extremely old) installation of TeX. If you are using TeX Live, you can use tlmgr to install it. If MiKTeX, you can use its package manager (or configure it to install on-the-fly). If you have a really old version, update your TeX installation. – cfr Jan 23 '15 at 0:34
  • I am using MikTex, My system says "the forest.sty not found"!!!! I tried MikTex package manager, but there is not forest.sty!! So where can I download it? – Yuming Feng Jan 23 '15 at 0:51
  • @YumingFeng I don't know anything about MiKTeX, I'm afraid, but there are plenty of questions and answers about it here which explain how to configure it. Make sure you have the current version (2.9 something?) and consider configuring it to install packages on-the-fly so that you don't have to worry about it. – cfr Jan 23 '15 at 1:11
3

Ignasi's answer to this question can be easily adopted here too.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{tikz-qtree}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.east)
-- +(8pt,0)
|- (\tikzchildnode)}}}
\begin{document}

\begin{tikzpicture}
\tikzset{grow'=right,level distance=1.5cm}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree [.\node(root){S}; [.\node(np){NP}; [.\node(d){Det}; \node(t){the}; ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P \node(o){on}; ]
[.NP [.Det the ] [.N \node(m){mat}; ] ] ] ] ]

\begin{scope}[every node/.style={align=left, anchor=center, font=\tiny\sffamily\bfseries,}]
 \node[above= 2mm of t] (thenode) {FOURTH};
 \node[at =(thenode-|root)] {FIRST};
 \node[at =(thenode-|np)] {SECOND};
 \node[at =(thenode-|d)] {THIRD};
 \node[at =(thenode-|o)] {FIFTH};
 \node[at =(thenode-|m)] {SIXTH};

\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

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.