3

I am using nodes and edges to draw some trees (of proofs) and would like to have a rectangular merge of two nodes into another, something like

A          B
|          |
+----+-----+
     |
     C

From A to the cross point I could use (a) |- (cross) but what I really want is something like A |-| C.

Thanks

Norbert (my first questions here I guess ;-)

norbert
  • 8,235
  • 4
  • 1
    TikZ can draw trees. But I guess the hip thing today is to use forest package – percusse Feb 15 '16 at 12:56
  • 1
    @percusse For one, there's less typing involved. :P – Alenanno Feb 15 '16 at 15:21
  • We really need a complete example, though. forest is not really suitable for graphs as opposed to trees. If a single child has multiple parents, it is not a tree and may best be drawn in some other way. (Although you can sometimes use forest to good effect.) – cfr Feb 15 '16 at 22:58
  • You can't say |-| because it doesn't make sense. How would TikZ know how much vertical distance to do before the horizontal bit and how much after? |- and -| make sense because they say do all of the vertical then all of the horizontal or vice-versa. – cfr Feb 15 '16 at 22:59
  • You can as one sees in the solution linked in the first comment defining two styles |-| and -|- – norbert Feb 15 '16 at 23:31

1 Answers1

1

With forest, you can do something like this, but note that the root of the tree is now C. If the image in the question is a genuine tree, this must be the case because a child must have exactly one parent. If that's not the case, then it is a graph but it is not of the specific graph species tree. In that case, forest may not be the best option since it is dedicated specifically to the drawing of trees.

\documentclass[tikz,multi,border=5pt]{standalone}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\forestapplylibrarydefaults{edges}
\begin{forest}
  forked edges,
  for tree={
    grow'=north,
  }
  [C[A][B]]
\end{forest}
\end{document}

forked tree

You can also use the trees TikZ library, although the syntax for specifying trees is considerably more verbose in that case.

cfr
  • 198,882
  • Thanks, this looks nice and concise, I will check out the documentation, because I need also normal diagonal and unary vertical edges, too. I have for now used the solution from the vertical and horizontal lines in pgf solution with |-|, that works great. – norbert Feb 15 '16 at 23:30
  • 1
    @norbert You say e.g. B, forked edge and remove forked edges from the preamble of the tree to make just that particular edge forked. – cfr Feb 15 '16 at 23:32