12

I have recently switched from the tikz_qtree package to forest. Now I'm trying to change my trees to fit the forest coding. However, I can't find the way to let a single node contain two lines. I do not want the I-node in my example to branch to are. In the tikz-qtree package this could be done with the command:

\tikzset{every tree node/.style={align=center,anchor=north}}



 \documentclass[12pt]{article}
 \usepackage[utf8x]{inputenc}
 \usepackage{forest}
 \usepackage{ucs}
 \usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
 \geometry{a4paper} 
 \usepackage{gb4e}
 \usepackage{flexisym}

 \begin{document}

\begin{exe}
\ex
\begin{forest}, baseline
[IP, 
[Spec]
[I\textprime,
    [I \\ are]
    [VP]
]]
 \end{forest}
 \end{exe}

\end{document}
12

To do this in forest you also need to tell it to align node text as center. I've added a qtree style which does this for every node and also makes the branches join unlike the default forest style, which is IMO somewhat ugly.

\documentclass[12pt]{article}
\usepackage{forest}
\forestset{qtree/.style={for tree={parent anchor=south, 
           child anchor=north,align=center,inner sep=0pt}}}
\usepackage{flexisym}

\begin{document}

\begin{forest}, baseline, qtree
[IP 
[Spec]
[I\textprime,
    [I\\are]
    [VP]
]]
 \end{forest}

\end{document}

output of code

  • What do you mean by 'must be bracketed'? You don't need the curly brackets around the multiline node, by the way. – cfr Apr 16 '15 at 2:55
  • Yes you're right. And the extra code in my tree was just a leftover. So now my answer looks like yours. – Alan Munn Apr 16 '15 at 22:16
  • I've changed my answer so it just makes the point about adding baseline to the style. I did delete it completely but then thought that bit might be useful. I'll delete if you prefer, though. – cfr Apr 16 '15 at 22:35
  • It doesn't matter to me. I was too busy at the time of your original comment to respond otherwise I would have corrected this sooner. – Alan Munn Apr 17 '15 at 3:28
5

This is a small supplement to Alan Munn's solution. If all of your trees styled with qtree should be aligned with baseline, you can add this to the qtree style also:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\forestset{
  qtree/.style={
    baseline,
    for tree={
      parent anchor=south,
      child anchor=north,
      align=center,
      inner sep=1pt,
    }}}
\usepackage{flexisym}

\begin{document}

\begin{forest}
  qtree,
  [IP
    [Spec]
    [I\textprime,
        [I\\are]
        [VP]
    ]
  ]
\end{forest}

\end{document}

simpler code

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.