TransWikia.com

TikZ forest - Align extra contents added on the right of the final nodes

TeX - LaTeX Asked on August 29, 2021

To explain "probabilistic" tree, I would like to add extra texts. I would like to align vertically all this extra texts. Is it feasible?

Is it also possible to have perfect baseline alignment between node and its extra content?

Does the package forest give easy to use names to the nodes of the tree?

documentclass[12pt]{article}

RequirePackage{forest}
useforestlibrary{linguistics}

forestset{
  extra/.style={
    edge label={
      node [xshift=1.5cm] {$leftarrow$ #1}
    }
  }
}

begin{document}

begin{forest}
  for tree = {%
    sn edges,
    grow'  = 0,
    anchor = parent,
  },
  [
    [A
      [B, extra=b]
      [C, extra=c]
    ]
    [D
      [E, extra=e]
      [F
        [G, extra=g]
        [H, extra=h]
      ]
    ]
  ]
end{forest}

end{document}

One Answer

A pointer in the right direction -- instead of extra style a write me style is defined taking the forest tree as in a bounding box--the inward pointing arrows can (later) be modified to cater for the the length from tagZ to nodeB from--

https://tex.stackexchange.com/a/398722/197451

enter image description here

documentclass[12pt]{article}

RequirePackage{forest}
useforestlibrary{linguistics}

forestset{
  extra/.style={
    edge label={
      node [xshift=1.5cm] {$leftarrow$ #1}
    }
  }
}

begin{document}

begin{forest}
  for tree = {%
    sn edges,
    grow'  = 0,
    anchor = parent,
  },
write me/.style={
    tikz+={
        node [anchor=mid west, red] at (.mid -| write me coord) {$leftarrow$ #1};
    },
},
tikz+={
    coordinate (write me coord) at (current bounding box.east);
}
  [
    [A
      [B, write me=tag Z]
      [C, extra=c]
    ]
    [D
      [E, extra=e]
      [F
        [G, extra=g]
        [H, write me=tag T]
      ]
    ]
  ]
end{forest}

end{document}

Correct answer by js bibra on August 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP