4

I am trying to reproduce this graph:

leaf aligned

I've read in tikz-qtree documentation that I need to compute the size from the root as a multiple of level distance, but I can get it to work. So far I have:

\documentclass[ twoside,openright,titlepage,numbers=noenddot,headinclude,%1headlines,% letterpaper a4paper
            footinclude=true,cleardoublepage=empty,abstractoff, % <--- obsolete, remove (todo)
            BCOR=5mm,paper=a4,fontsize=11pt,%11pt,a4paper,%
            ngerman,american,%
            ]{scrreprt}

\usepackage{tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{arrows,decorations.markings,babel}
\begin{document}
\begin{tikzpicture}[every node/.style={align=left}]
  \tikzset{
    edge from parent/.style={
      draw,edge from parent
      path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
    },
%    level 2/.style={level distance=50pt},
%    frontier/.style={distance from root=150pt} % Align leaf nodes
  }

   \Tree [.S
             [.NP
                [.Rolls-Royce ] [.Motor ] [.Cars ] [.Inc ]
             ]
             [.VP
                [.said ]
                [.SBAR
                   [.NONE ]
                   [.S
                      [.NP [.it ] ]
                      [. VP
                         [.expects ]
                         [.S
                            [.NP
                               [.its ] [.U.S ] [. sales ]
                            ]
                            [.VP
                               [. to ]
                               [. VP
                                  [.remain ]
                                  [.ADJP [. steady ] ]
                                  [.PP
                                     [.at ]
                                     [.NP
                                        [.QP [.about ] [.1200 ] ]
                                        [.cars ]
                                     ]
                                  ]
                               ]
                            ]
                         ]
                      ]
                   ]
                ]
             ]
            ]
\end{tikzpicture}
\end{document}

But the result is this (does not fit the page):

my result

What I am doing wrong?

So far I tried this recomendations:

  • 1
    Welcome! It is helpful if you can post a complete minimal example i.e. with the preamble etc. needed to compile the document so people don't have to guess which packages, which class, how big the paper is that the tree is going off of, etc. – cfr Nov 25 '16 at 18:13
  • Done! best regards. – ElBaulP Nov 25 '16 at 18:22
1

May I suggest Forest for the tree and sidewaysfigure for the placement?

First, the tree:

\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges,linguistics]{forest}
\begin{document}
\begin{forest}
  forked edges,
  where n children=0{tier=terminus}{},
  [S
     [NP
       [Rolls-Royce\\NNP]
       [Motor\\NNP]
       [Cars\\NNPS]
       [Inc\\NNP]
     ]
     [VP
       [said\\VBD]
       [SBAR
         [-NONE-]
         [S
           [NP
             [it\\PRP]
           ]
           [VP
             [expects\\VBZ]
             [S
               [NP
                 [its\\PRP\$]
                 [U.S\\NNP]
                 [sales\\NNS]
               ]
               [VP
                 [to\\TO]
                 [VP
                   [remain\\VB]
                   [ADJP
                     [steady\\JJ]
                   ]
                   [PP
                     [at\\IN]
                     [NP
                       [QP
                         [about\\IN]
                         [1200\\CD]
                       ]
                       [cars\\NNS]
                     ]
                   ]
                 ]
               ]
             ]
           ]
         ]
       ]
     ]
   ]
\end{forest}
\end{document}

Forest tree

Even set sideways, the tree is too wide. Rather than scaling it, which should be a choice of last resort, it would be better to use a smaller font size, such as \scriptsize and to reduce the space between the nodes by changing s sep. Making these changes, the tree fits and will be more legible than one which was simply scaled. This is especially true if you are using optically sized fonts.

fitting tree

\documentclass[twoside,openright,titlepage,numbers=noenddot,headinclude,  footinclude=true,cleardoublepage=empty,abstractoff,BCOR=5mm,paper=a4,fontsize=11pt,ngerman,american]{scrreprt}
\usepackage[edges,linguistics]{forest}
\usepackage{rotating}
\begin{document}
\begin{sidewaysfigure}
  \centering
  \scriptsize
  \begin{forest}
    forked edges,
    where n children=0{tier=terminus}{},
    for tree={
      s sep'=1pt,
    },
    [S
      [NP
        [Rolls-Royce\\NNP]
        [Motor\\NNP]
        [Cars\\NNPS]
        [Inc\\NNP]
      ]
      [VP
        [said\\VBD]
        [SBAR
          [-NONE-]
          [S
            [NP
              [it\\PRP]
            ]
            [VP
              [expects\\VBZ]
              [S
                [NP
                  [its\\PRP\$]
                  [U.S\\NNP]
                  [sales\\NNS]
                ]
                [VP
                  [to\\TO]
                  [VP
                    [remain\\VB]
                    [ADJP
                      [steady\\JJ]
                    ]
                    [PP
                      [at\\IN]
                      [NP
                        [QP
                          [about\\IN]
                          [1200\\CD]
                        ]
                        [cars\\NNS]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  \end{forest}
\end{sidewaysfigure}
\end{document}
  • Thanks! I resolved the problem of not fitting in the page with resizebox, but now I've tried your tip on reducing the font size, it is better. Regards! – ElBaulP Nov 26 '16 at 6:20
1

It's working now!

\begin{figure}[h]
\resizebox{1.3\textwidth}{!}{%
\begin{tikzpicture}[every node/.style={align=center}]
  \tikzset{
    edge from parent/.style={
      draw,edge from parent
      path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
    },
    frontier/.style={distance from root=350pt} % Align leaf nodes
  }

   \Tree [.S
             [.NP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS Inc\\NNP ]
             [.VP said\\VBD
                [.SBAR -NONE-
                   [.S
                      [.NP it\\PRP ]
                      [. VP expects\\VBZ
                         [.S
                            [.NP its\\PRP\$ U.S\\NNP sales\\NNS ]
                            [.VP to\\TO
                               [.VP remain\\VB
                                  [.ADJP steady\\JJ ]
                                  [.PP at\\IN
                                     [.NP
                                        [.QP about\\IN 1200\\CD ]
                                        cars\\NNS
                                     ]
                                  ]
                               ]
                            ]
                         ]
                      ]
                   ]
                ]
             ]
         ]
\end{tikzpicture}
}
\end{figure}

Working!

The problem was was adding as nodes the leafs like so:

[.NP [.Rolls-Royce ] [.Motor ] [.Cars ] [.Inc ] ]
% The correct way
[.NP Rolls-Royce Motor Cars Inc ]

UPDATE

Folowing the advice of CFR I've made a few adjustements:

  • Removed resizebox
  • Decrease font size to tiny
  • Reducing distance between internal edges

The code and result:

\begin{figure}[h]
\tiny
\begin{tikzpicture}[every node/.style={align=center}]
  \tikzset{
    edge from parent/.style={
      draw,edge from parent
      path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
    },
    frontier/.style={distance from root=208pt}, % Align leaf nodes
    level 1+/.style={level distance=18pt} % Distance between levels
  }

   \Tree [.S
             [.NP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS Inc\\NNP ]
             [.VP said\\VBD
                [.SBAR -NONE-
                   [.S
                      [.NP it\\PRP ]
                      [. VP expects\\VBZ
                         [.S
                            [.NP its\\PRP\$ U.S\\NNP sales\\NNS ]
                            [.VP to\\TO
                               [.VP remain\\VB
                                  [.ADJP steady\\JJ ]
                                  [.PP at\\IN
                                     [.NP
                                        [.QP about\\IN 1200\\CD ]
                                        cars\\NNS
                                     ]
                                  ]
                               ]
                            ]
                         ]
                      ]
                   ]
                ]
             ]
         ]
\end{tikzpicture}
\end{figure}

enter image description here

UPDATE #2

I've made another small change in order to make it look more like the original. The None leaf should be at level 3, not aligned with the rest of the sentence. For that, the only change that needs to be made is:

[.SBAR [.none ]
% instead of 
[.SBAR NONE 

Result:

final

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.