3

following on from previous question

Example Problem:

\documentclass[margin=3mm]{standalone}%
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}
    \begin{forest}
for tree={
inner xsep=0pt,
s sep=9mm,
l sep=7mm}
    [VP
    [DP]
      [V'
        [A, name=a]
        [DP]
      ]
]
\begin{scope}[inner xsep=0pt, node distance=7mm and 0mm]
\node (b) [right=of a] {B};
\node (c) [right=of b] {C};
\node (x) [below=of c] {XXX};
\draw (c) -- (x);
\end{scope}
    \end{forest}
\end{document}

XXX is now below ABC but if I want to do these sort of rearrangements at multiple levels (e.g. XXX now should point to the 1 in 123 in a node at a level below, and the 3 then points to node below it, can I do it in forest, or do I need to manually build the tree in tikz?

https://i.stack.imgur.com/rKXLl.png

2

You can do that all within forest without having to resort to place extra stuff with TikZ methods. One possibility is to play with anchors, note that there are different anchors: node anchors, child anchors and parent anchors.

\documentclass[margin=3mm]{standalone}%
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}
    \begin{forest}
for tree={
inner xsep=0pt,
s sep=9mm,
l sep=7mm}
    [VP
    [DP]
      [V'
        [ABC, name=a,parent anchor=-45
         [XXX,anchor=135]]
        [DP]
      ]
]
    \end{forest}
\end{document}

enter image description here

The numbers are just angles. In order to make V' connect to A in ABC just add ,child anchor=120.

\documentclass[margin=3mm]{standalone}%
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}
    \begin{forest}
for tree={
inner xsep=0pt,
s sep=9mm,
l sep=7mm}
    [VP
    [DP]
      [V'
        [ABC, name=a,parent anchor=-45,child anchor=120
         [XXX,anchor=135]]
        [DP]
      ]
]
    \end{forest}
\end{document}

enter image description here

  • Can you explain how you choose those numbers, and also show how to get the edge from V' to land at A in the ABC? – Andrew Swann Jun 15 '18 at 17:35
  • @AndrewSwann The numbers are just angles and I added this feature as well. (I was too sloppy and did not read this requirement.) – user121799 Jun 15 '18 at 17:42
  • And to get the line vertical it is important that "anchor - parent anchor = 180" – Andrew Swann Jun 15 '18 at 17:46
  • @AndrewSwann Yes and no. In this case yes, because both nodes have the same width, but in general no. However, you can also adjust the grow direction on the way as detailed on p. 42 of the forest manual. Of course, you can completely change the layout, but then I guess the OP needs to slightly rephrase the question. – user121799 Jun 15 '18 at 17:51

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.