2

I've been looking for a TikZ example for a while now that looks something like the attached powerpoint picture. I can't imagine that nobody has done something similar. I tried adapting this example, but failed...

powerpoint

Does anybody have an idea where I can find a similar diagram?

Is there a way to just add the LaTeX table enviroment into a TikZ picture?

  • Please provide the code you've tried so people don't have to create your example from scratch! – cfr Nov 26 '14 at 23:02
2

Here is a solution using forest.

It makes no sense to use a float in this context, so the tabulars cannot benefit from the automatic numbering of the table environment. However, you can arrange to have them numbered automatically and added to the list of tables. To do this, you need to be a little careful when the counter is incremented and when the contents line written. In the code below, this is done when the label itself is typeset.

The tabulars are placed in regular nodes, just surrounded by curly brackets.

The dashed line and level labels are added after the tree is drawn. The name key provided by forest is used to help with positioning, and a brace TiKZ decoration is used for the lines required here. calc is used to compute positions for the level labels themselves.

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing,calc}
\begin{document}

\forestset{
  my level/.style={
    where n=1{
      name/.wrap pgfmath arg={level ##1}{level()},
    }{},
  },
  my circle/.style={
    shape=circle,
    fill,
    minimum size=1.5pt,
    inner sep=0pt,
    outer sep=0pt,
  },
  my tabular/.style={
    no edge,
    for children={
      edge={draw, ->},
    },
    for parent={
      l sep=0pt,
      for tree={
        fit=band,
      },
      for parent={
        calign=child,
        calign child=2,
      },
    },
    ->,
  },
  my tabular label/.style={
    label={\stepcounter{table}\addcontentsline{lot}{table}{\numberline {\thetable}{\ignorespaces Table \thetable}}\footnotesize Table \thetable},
  },
  /tikz/my label/.style={
    font=\scriptsize,
    midway,
  },
}

\begin{forest}
  for tree={
    grow=east,
    parent anchor=east,
    child anchor=west,
    anchor=center,
    align=center,
    where level=0{
      draw,
    }{
      my level,
    },
  }
  [Text, name=my root, l sep+=10pt
    [, my circle, edge label={node [my label, below] {\dots}}]
    [, my circle]
    [, my circle
      [, my circle, edge label={node [my label, below] {\dots}}]
      [, my circle]
      [, my circle
        [{\begin{tabular}{|c|c|c|}
            \hline
              aaa & bbb & ccc\\\hline
                &   &   \\\hline
                &   &   \\\hline
              \end{tabular}}, my tabular, my tabular label
          [{\begin{tabular}{|c|c|c|}
              \hline
                aaa & bbb & ccc\\\hline
                  & &   \\\hline
                  & &   \\\hline
            \end{tabular}}, my tabular label
          ]
        ]
      ]
    ]
  ]
  \path [draw, dashed] (level 1.center |- current bounding box.north) +(0,10pt) -- (level 1.center |- current bounding box.south) -- +(0,-10pt) coordinate (bot);
  \path [draw, decoration=brace, decorate]
    (level 1.west |- bot) coordinate (c1) -- (my root.east |- bot) coordinate (c2) ;
  \path [draw, decoration=brace, decorate]
    (level 2.west |- bot) coordinate (c3) -- (level 1.east |- bot) coordinate (c4);
    \node [anchor=north] at ($(c1)!1/2!(c2)$) {Text};
    \node [anchor=north] at ($(c3)!1/2!(c4)$) {Text};
\end{forest}
\listoftables

\end{document}

decision tree with tabulars

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.