1

I would like to draw a tree where the position of edge endpoints relative to the node depends on contents of the node, and may change between the parent edge and the child edges, to point out a relationship between the two labels. Here is an example of what I want to draw:

good

Note that the child edges of the middle node are positioned differently from that of its own child edges. (Fortunately, I can assume that all of a node's child edges should be positioned at the same position: it is the case in this example, but it would not be the case if, e.g., the middle node "S(b, c)" had a child "V(b, f)".

Is there a clean way to draw this kind of tree?

Edit: My current approach is to use tikz-qtree:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree
[.{$R(a, b)$}
  [.{$S(b, c)$}
    [.{$T(c, d)$} ]
    [.{$U(e, c)$} ]
  ]
];
\end{tikzpicture}
\end{document}

With the expected result:

bad

The problem is that the tree edges do not represent clearly the common elements from one node label to the other. Sadly I do not have much experience with Tikz or qtree so I don't have a specific idea of how to improve this...

4
  • Welcome to TeX.SX! Have you tried anything so far? If you have code you can post, it would help us to see what you need help with.
    – Adam Liter
    Commented Nov 25, 2014 at 18:17
  • Thanks! I added a sample, not sure if it helps.
    – a3nm
    Commented Nov 25, 2014 at 21:25
  • Can you complete the code, please? So we have something to copy-paste-compile and play with. That makes it easier to help, helps to minimise misunderstandings and makes it more likely you will get help. Also, do you need a tikz-qtree solution or could another solution be used?
    – cfr
    Commented Nov 25, 2014 at 22:12
  • I don't really need a tikz-qtree solution, I edited the post to reflect this. Thanks for completing the example! :)
    – a3nm
    Commented Nov 26, 2014 at 7:58

1 Answer 1

1

This uses forest and it takes significant amounts of manual intervention to work. However, it is the best I can come up with right now. (I don't know tikz-qtree at all and I could not see any way to achieve this from the documentation. qtree might be a possibility as it allows you to execute TeX code using ! but then you would lose the power of TiKZ within the tree itself.)

\documentclass[border=5pt, tikz, mult]{standalone}
\usepackage{forest}
\begin{document}

  \begin{forest}
    for tree={
      inner sep=1pt
    }
    [{$R(a, b)$}, parent anchor=-35, anchor=-35
      [{$S(b, c)$}, parent anchor=-40
        [{$T(c, d)$}, child anchor=90
        ]
        [{$U(e, c)$}, child anchor=45
        ]
      ]
    ]
  \end{forest}

\end{document}

aligned tree

2
  • Thanks a lot! That's much better than what I had, but it does require a lot of manual tweaks. Also, the use of anchor means that the distance between each level (which seems to be computed between the anchor) now depends on the anchor position, so it varies a bit across the tree, which is ugly: see i.imgur.com/00zk7YM.png obtained by paste.fulltxt.net/=uuowKt. Is there a way to avoid this?
    – a3nm
    Commented Nov 26, 2014 at 8:46
  • @a3nm Yes, I couldn't agree more - I hope somebody will provide a better answer soon!
    – cfr
    Commented Nov 26, 2014 at 22:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .