3

I am basically trying to re-create the Aves Cladogram as illustrated in this wikipedia page.

After trying to use Newicktree package for a while, I decided to migrate to forest.

I am trying to make an horizontal and squared edge tree combining answer from Square edges in forest package and how could we create this tree diagram?.

Here is my current code:

\documentclass[tikz]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree={
    edge path={\noexpand\path[\forestoption{edge}](\forestOve{\forestove{@parent}}{name}.parent anchor) -- +(0,-12pt)-|     (\forestove{name}.child anchor)\forestoption{edge label};},
    grow=0,
    reversed, % tree direction
    parent anchor=east,
    child anchor=west, % edge anchors
}
[VP
    [DP,tier=word]
    [V’
        [V,tier=word]
        [DP,tier=word]
    ]
]
\end{forest}

\end{document}

And as expected the result is not desirable:

Imgur

My guess is that I should modify -- +(0,-12pt)-|, but I don't know how ! Many thanks for your help !

4

Your answer will work but is needlessly verbose as you can simply use relative node names to specify the edge path.

      \noexpand\path[\forestoption{edge}](!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};},

(!u) refers to the parent of the current node. () refers to the current node.

You can also align the terminal nodes for the whole tree in the preamble:

    if n children=0{tier=word}{}

but anchoring the nodes at the left side makes for a neater tree:

    anchor=west,

The result:

neater tree

Complete code:

\documentclass[tikz]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree={
    edge path={
      \noexpand\path[\forestoption{edge}](!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};},
    grow=0,
    reversed, % tree direction
    parent anchor=east,
    child anchor=west, % edge anchors
    anchor=west,
    if n children=0{tier=word}{}
}
[VP
    [DP]
    [V’
        [V]
        [DP]
    ]
]
\end{forest}
\end{document}
  • However, I have a little offset for some entry on last entry (last right element). see code and pdf – Rafnuss Nov 20 '15 at 13:01
  • Sorry, but I'm not sure what you're asking. Are you saying that your tree should or shouldn't look like that?! You probably don't want to set the children's anchors to north when nodes are empty, though. west would be better here. – cfr Nov 20 '15 at 13:24
  • I can't compile your full code: I get an error about too large a dimension. – cfr Nov 20 '15 at 13:26
  • 1
    @Rafnuss delay={where content={}{shape=coordinate,for parent={for children={anchor=west}}}{}} solves both the compilation error and the alignment problem for me. (Assuming the alignment was a problem, and not intended - as I say, I wasn't clear on that.) – cfr Nov 20 '15 at 13:28
  • @Rafnuss Output with adjustment. – cfr Nov 20 '15 at 13:29
1

Actually, tikz is not that bad...

After looking a little more at the manuel and few test here it is -- +(8pt,0) |- or complete version:

edge path={\noexpand\path[\forestoption{edge}] (\forestOve{\forestove{@parent}}{name}.parent anchor) -- +(8pt,0) |- (\forestove{name}.child anchor)\forestoption{edge label};}

Imgur

From what i understand, -- is for drawing a line, +(x,y) is the lenght of the line and -| or |- for perpendicular line either vertical or horizontal. So -- +(8pt,0) create the small horizontal line from the parent node and |- make the perpendicular line.

I still don't know how the two end of line (from perpendicular line to child node) is drawn...

  • 2
    |- actually makes two line segments (vertical first, and then horizontal) and so does -|, but in reverse order. – Sašo Živanović Nov 18 '15 at 16:54

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.