3

I want to draw a binary tree using TiKZ (more exactly a rooted binary DAG, but there is only one occurence of node with two parents). I managed to obtain a tree using the standard TiKZ graph layouts:

tentative tree

Here is the corresponding code (to compile with LuaTeX):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
  \begin{scope}%
[every node/.style={draw,circle}]
\graph [fresh nodes, math nodes] {
  b -> {
    c ->{ 
      b -> {
        "\Lambda", "\emptyset"
      },
      "\emptyset"
    }, 
    a -> {
      b -> {
        a -> {
          "\Lambda", "\emptyset"
        },
        a -> {
          M0/a -> {
            "\Lambda", 
            c -> {
              "\Lambda", "\emptyset"
            }
          },
          "\emptyset"
        }
      },
      c -> {
        a -> {
          (M0),
          "\emptyset"
        },
        "\emptyset"
      }
    }
  }
};
\end{scope}
\end{tikzpicture}
\end{document}

however the tree would be more legible if the "left" child of a node is placed under its parent (with the exception of the node pointing to another part of the graph), and the "right" child of a node is placed on its right. Note that this behavior is reversed in my tentative…

Is there some way to parameterize graphs to obtain this?

scand1sk
  • 141

1 Answers1

1

Not entirely satisfactory, but I could obtain the layout I wanted by relying on manual positioning. Here is the result. I am still interested in a more "clever" solution.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees,positioning}
\begin{document}
\begin{tikzpicture}
  \begin{scope}%
    [every node/.style={draw,circle},inner sep=.1em]
    \graph [Cartesian placement,fresh nodes, math nodes, grow right=.8] {
      rb/b -> [dashed] ra/a [x=.8] -> [dashed] rc/c [x=3.2] -> [dashed] "\emptyset" [x=3.2];
      (rb) -> cb/c ->[dashed] "\emptyset";
      (cb) -> b -> [dashed]  "\emptyset";
      (b) -> l0/"\Lambda" [x=2] ;
      (ra) -> ba/b [x=1.6,y=3] ->[dashed] aaac/a [x=2.4,y=3,fill=lightgray] ->[dashed] "\emptyset" [x=2.4,y=3];

      (ba) -> a [x=1.6,y=3] ->[dashed] "\emptyset" [x=1.6,y=3];
      (a) -> (l0);

      (aaac) -> auc/a [x=3.2,y=4] ->[dashed] c [x=3.2,y=4] ->[dashed] "\emptyset" [x=3.2,y=4];

      (auc) -> (l0) ;
      (c) -> (l0);

      (rc) -> aaac2/a [x=4.8,y=6,fill=lightgray] ->[dashed] "\emptyset" [x=4.8,y=6];

      (aaac2) -> [out=-90,in=90] (auc);
   };
  \end{scope}
\end{tikzpicture}
\end{document}%    

resulting graph

scand1sk
  • 141