I'm getting very odd output from some of my forest trees. Here's a minimalish example:

     label=right:{\itshape bounding node}},
default preamble={for tree={inner sep=0pt,s sep=.25in}},
[CP [DP\\{Who_{i}},name=SPEC ] [\ibar{C} [C\\was_{j} ] [TP,bnode [{DP_{k}},name=SUBJ,bnode  [D\\{a} ] [NP  [N\\story ] [PP [P\\about ] [DP\\{\trace{who}},name=TRACE ] ] ] ]  [\ibar{T} [T\\t_{j} ] [VP [VP [V\\written ] [DP\\t_{k} ] ] [PP [P\\by ] [DP\\John ] ] ] ] ] ] ]
\draw[->,thick,dashed,red] (TRACE.south) to [bend left=120] node[rotate=45] {{\large\textbf{=}}} (SPEC.south);  

output of code

  • 1
    Something to do with fit=() it seems, remove that and the "extra tree" is gone. – Torbjørn T. Dec 10 '17 at 0:26
  • The code compiles well in ShareLaTeX. No strange behavior nor odd output. – Cragfelt Dec 10 '17 at 0:26
  • @TorbjørnT. Thanks! I'll go with that for the moment as a workaround. – Alan Munn Dec 10 '17 at 0:33
  • 3
    I just had a look at that, TL2016, forest v2.1.4. (I have v2.1.5 on my computer, with TL17). – Torbjørn T. Dec 10 '17 at 0:37
  • 1
    @Cragfelt No worries, Torbjorn has already commented on the difference. – Alan Munn Dec 10 '17 at 1:04

fit is tikz's key in /tikz namespace. Forest implements fit to in /tikz namespace, which fits to nodes visited in a given nodewalk.

OP's definition of bnode doesn't work because it tries to fit a forest node, i.e. a node that is positioned by forest. Furthermore, it tries to size/position it in terms of itself: fit=() is processed while typesetting the node and () refers to the current forest node, i.e. the "calling" node itself. (Note that the code wouldn't work even if there was no self-reference, as each forest node is typeset "alone" and only later positioned in the correct location. One cannot refer to other forest nodes when a forest node is typeset.)

Both tikz's /tikz/fit and forest's /tikz/fit to are meant to be used in "normal" tikz nodes, i.e. nodes not positioned by forest. So, the definition of bnode should be the following.

          label=right:{\itshape bounding node}]{};

This works because the tikz code is executed after the node is already drawn (actually, all nodes are). But forest knows which forest node the code originates from, and () refers to that node. (Note that forest hacks into tikz implicit coordinate system to make this reference possible; package option tikzcshack disables the hack.)

In this example, the "normal" fit is quite enough for the job, but one could use fit to as well, like this:

    \node[draw=red,thick,fit to=current,circle,
          label=right:{\itshape bounding node}]{};

This could be easily modified to have the circle contain both the node and its parent, for example:

    \node[draw=red,thick,fit to={current,parent},circle,
          label=right:{\itshape bounding node}]{};
  • Thanks for the explanation Sašo. I think what happened was my original code used tikz+ but simplified it with the resulting leftover fit=(). – Alan Munn Dec 11 '17 at 14:36
  • @AlanMunn Which is what I was trying to say, too. (Less the details about Forest's node-building.) But I still suspect that having underscores active in forest isn't a good idea. Sašo, is that really safe? – cfr Dec 11 '17 at 22:33
  • 1
    Off-topic: definition of repeat on page 61 is incorrect, I think. The first argument is evaluated as Forest math and not pgfmath (except that that's the default). – cfr Dec 11 '17 at 22:37
  • @cfr I routinely use active underscores in forest trees as I'm sure do (under)scores :) of linguists without any problems. – Alan Munn Dec 11 '17 at 23:16
  • @AlanMunn I guess with Forest math you can avoid them now by just avoiding pgfmath in those cases. Or are you saying it doesn't matter when you use them in Forest keys either? n_children or whatever? – cfr Dec 12 '17 at 23:34

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.