Tdtr: how can I avoid the gap between branches in a syntax tree

As a sometime Linguistics lecturer I am interested in Tdtr: a package for drawing beautiful tidy tree easily (particularly to recommend Typst to former students). However, having taken the example syntax tree given in the docs, I tried modifying it to label it with a sort of logical rather than syntax structure:

#tidy-tree-graph(
  draw-node: (stroke: none),
  draw-edge: (
    tidy-tree-draws.south-north-draw-edge,
    (marks: "-")
  )
)[
  #let sink(n) = node-attr(sink: n)
  - Sentence
    - Subject
      - Determiner
        - The #sink(2)
      - Modifier
        - big #sink(2)
      - Head
        - dog #sink(2)
    - Predication
      - Head
        - barked #sink(2)
      - Qualifier
        - Head
          - at #sink(1)
        - Complement
          - Determiner
            - the
          - Head
            - mailman
]

I notice that at the top level, the two lines no longer meet:

Could someone explain this and how to correct it for me, please?

:slight_smile:
Mark

A quick way would be to:
- #h(5pt)Sentence#h(5pt)

The documentation is quite lenghty, one would have to dive into it as there may be another way. The node stroke is set to none, normally the edges would reach the box around the node but they aren’t. If the word gets longer, the edges are adjusting in the place you want.

N.B. This is a Showcase thread, ideally this would be posted in Questions [mod comment: this thread was split off]

Thanks very much for this answer.

Firstly, apologies if you think this is in the wrong place; I posted here because I thought this must be something more fundamental with the package, rather than a user question. If you feel it should be moved to Questions feel free to do so.

The point of interest is that this only happens at the root level; the edges reach the boxes around the nodes Subject, Predication, Qualifier and Complement. It is only at the root level that this doesn’t happen if the label (again I apologise for not knowing what is the right term in fletcher) is more than 1 character.

Looking at it more closely, it’s as if the tidy-tree-draws.south-north-draw-edge instruction is not applied to the root node.

:slight_smile:
Mark

Actually, it’s not a bug of tdtr, but a bug from fletcher. I have found this bug some time before, and I was also confused about the weird behavior, but I didn’t go into depth at the time.

Now I find this the root cause of this problem. It happens when the x-coordinate value of a node is exactly in the spacing of the nodes, like this:

So a possible way to alleviate this problem is to set the spacing of the x-coordinates to 0pt, like this:

#tidy-tree-graph(
  draw-node: (stroke: none),
  draw-edge: (
    tidy-tree-draws.south-north-draw-edge,
    (marks: "-")
  ),
  spacing: (0pt, 15pt),
)[
  #let sink(n) = node-attr(sink: n)
  - Sentence
    - Subject
      - Determiner
        - The #sink(2)
      - Modifier
        - big #sink(2)
      - Head
        - dog #sink(2)
    - Predication
      - Head
        - barked #sink(2)
      - Qualifier
        - Head
          - at #sink(1)
        - Complement
          - Determiner
            - the
          - Head
            - mailman
]

However, this cannot completely solve the problem. An extreme example is like this:

#tidy-tree-graph(
  draw-node: (stroke: none),
  draw-edge: (
    tidy-tree-draws.south-north-draw-edge,
    (marks: "-"),
  ),
  spacing: (0pt, 15pt),
)[
  #let sink(n) = node-attr(sink: n)
  - S
    - NP
      - NP
        - Det
          - The #sink(4)
        - Adj
          - old #sink(4)
        - N
          - man #sink(4)
      - PP
        - P
          - with #sink(4)
        - NP
          - Det
            - a #sink(3)
          - Adj
            - walking #sink(3)
          - N
            - stick #sink(3)
    - VP
      - AdvP
        - Adv
          - suddenly #sink(4)
      - V
        - realized #sink(5)
      - S'
        - Comp
          - that #sink(4)
        - S
          - NP
            - Det
              - his #sink(2)
            - N
              - dog #sink(2)
          - VP
            - Aux
              - had #sink(2)
            - Aux
              - been #sink(2)
            - V
              - chasing #sink(2)
            - NP
              - Det
                - a #sink(1)
              - N
                - squirrel #sink(1)
            - PP
              - P
                - in #sink(1)
              - NP
                - Det
                  - the
                - N
                  - park
]

The nodes with path S-NP and S-VP-S'-S-NP have the problem and I have not thought a way to solve this, since their x-coordinates lie exactly halfway between two integers, namely in the “spacing” of nodes.

4 Likes

In fact, this is due to the “defocus adjustment” which is enabled in fletcher by default - not a bug.

Edge defocusing is the automatic separation of edges connecting to very wide or tall nodes in order to reduce “bunching”. It is meant to make things look more relaxed and less cramped, but it is an entirely subjective adjustment and in this case unwanted.

I think it probably should not be enabled by default when connecting to anchors (like north or south) because that is indeed unexpected.

You can disable it with node-defocus: 0.

4 Likes

Wow, thank you so much for helping me correct the error! This really solved a problem that had been bugging me for weeks. I never would have guessed that it was actually caused by that defocus option!

1 Like

This is really a great hint!
Thank you very much for sharing this.