2

I'm new to forest. Is there a style (or a modification of what's below) which produces the alignment of empty terminal nodes F3 and F4 in Tree A just like in Tree B?

\documentclass{standalone}
\usepackage{forest}
%\forestset{nice nodes/.style={for tree={inner sep=0pt,s sep=.2in,align=center, anchor=north}},default preamble=nice nodes, }
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}

Tree A:

\begin{forest}
[
[DP, name=target[a labelled\\ subtree, roof]]  
[F$_4$P[F$_4$]
[F$_3$P[F$_3$]
[F$_2$P[F$_2$][\hspace{10pt}F$_1$P $\Rightarrow$ something, 
name=t[is there a way\\to move this label\\to the right?, roof]]]]]]]
\end{forest}

Tree B:

\begin{forest}
[
[DP, name=target[a labelled\\ subtree, roof]]  
[F$_4$P[F$_4$[$\emptyset$]]
[F$_3$P[F$_3$[]]
[F$_2$P[F$_2$][\hspace{10pt}F$_1$P $\Rightarrow$ something, 
name=t[I miss qtree, roof]]]]]]]
\end{forest}
\end{document}

A separate issue is the problem of moving a node label (F4P in the trees) to the right, so that it is not centered wrt to the node. Here is what I get:

enter image description here

PS. The skeleton I'm using tolerates qtree and tikz-qtree but does not want to tolerate arrows in neither qtree nor tikz-qtree in XeLaTeX, so I'll need to stick to forest, I guess. That's why I'm trying to have a nice proportional tree in forest rather than using simply qtree.

3
  • 2
    You don't have any labels in your tree. Really confused.
    – cfr
    Mar 30, 2017 at 1:20
  • @cfr -- I've edited the post. It should be clear now. "Labels" are the names of the nodes in the linguistic trees. The top-most node is the only one which I left unlabelled. Other labels in these two tree diarams are DP, F4P, F4, F3P, F3, F2P, F2, F1P=>something. Thanks.
    – oliver
    Mar 30, 2017 at 11:01
  • Thanks. It is a bit confusing because, in Forest's terms, nodes can have labels, though yours do not :-).
    – cfr
    Mar 30, 2017 at 12:14

2 Answers 2

3

I think for your main question, you probably just want to add fit=band to the tree.

<code>fit=band</code>

Note that anchor=center is default for linguistics.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[linguistics]{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=0pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
}
\begin{document}
\begin{forest}
  [
    [DP, name=target
      [nodes F$_3$ and F$_4$ do\\
      align appropriately\\
      (I think)\\
      wrt F$_2$, roof
      ]
    ]
    [F$_4$P
      [F$_4$]
      [F$_3$P
        [F$_3$]
        [F$_2$P
          [F$_2$]
          [\hspace{10pt}F$_1$P$\Rightarrow$something, name=t
            [is there a way\\to move this label\\to the right?, roof
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

I'm not quite sure what you want to shift where. What you are calling the node label is actually not a label, but the node content. Nodes can have labels and contents, so this may be a source of confusion.

You can shift the node at the bottom right right (or left). However, I'm not sure if that is really what you mean.

            [is there a way\\to move this label\\to the right?, roof, xshift=10pt
            ]

shifted right

To avoid a lopsided roof, we can redefine the edge path.

fix roof

            [is there a way\\to move this label\\to the right?, xshift=10pt, edge path'={(!u.parent anchor) ++(5pt,0) -- (.north east) -- (.north west) -- cycle}
            ]

If you need this a lot, a style would be convenient.

  shift with roof/.style={
    xshift=#1,
    edge path'={(!u.parent anchor) ++(#1/2,0) -- (.north east) -- (.north west) -- cycle}
  },

Then we can write just

            [is there a way\\to move this label\\to the right?, shift with roof=10pt
            ]

to produce the same output as above.

You can make the top less 'pointy' by increasing the distance between the root's children. Possibly a bit extreme:

less 'pointy'

  [, s sep'+=20pt

A bit less extreme may be better.

less extreme

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[linguistics]{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=0pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
  shift with roof/.style={
    xshift=#1,
    edge path'={(!u.parent anchor) ++(#1/2,0) -- (.north east) -- (.north west) -- cycle}
  },
}
\begin{document}
\begin{forest}
  [, s sep'+=10pt
    [DP, name=target
      [nodes F$_3$ and F$_4$ do\\
      align appropriately\\
      (I think)\\
      wrt F$_2$, roof
      ]
    ]
    [F$_4$P
      [F$_4$]
      [F$_3$P
        [F$_3$]
        [F$_2$P
          [F$_2$]
          [\hspace{10pt}F$_1$P$\Rightarrow$something, name=t
            [is there a way\\to move this label\\to the right?, shift with roof=10pt
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}
5
  • Excellent, thanks! This works! Btw, I did manage to add an annotation to the left of the node label (="content" in forest termiology) by using node[right] in the \draw command -- the solution taken directly from the last page of this: (ling.auf.net/lingbuzz/003391), as shown in my answer below. Thanks!
    – oliver
    Mar 30, 2017 at 21:39
  • 1
    @oliver Wouldn't label=right:annotation be easier?
    – cfr
    Mar 30, 2017 at 21:46
  • I don't know. Can you please modify my code below with this? I'll see how it works. Thanks.
    – oliver
    Mar 30, 2017 at 21:52
  • 1
    @oliver Just add label=right:annotation as an option to the node you want annotated. It will just get passed to TikZ's label when the node is constructed.
    – cfr
    Mar 30, 2017 at 21:54
  • Excellent! It works. Indeed, a more comfortable option. Thanks.
    – oliver
    Mar 30, 2017 at 22:00
1
\documentclass{standalone}
\usepackage{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=1pt, s sep=12pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}

\begin{forest}
 [
 [DP, name=target[nodes F$_3$ and F$_4$ do\\ not align vertically\\ wrt           F$_2$, roof]]  
 [F$_4$P[F$_4$]    [F$_3$P[F$_3$]
  [F$_2$P[F$_2$]    [F$_1$P, name=t[I miss qtree, roof]] 
{ \draw (.east) node[right]{$\Rightarrow$ \textit{adjective}}; } ]]]]]
   %\draw[->] (t) to[out=south west,in=south] (target);
\end{forest}
\end{document}

Which give me this:

enter image description here

0

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.