1

I'm looking to create something like this in Tikz environment. Any tips? help?

enter image description here

  • 4
    Hi. What have you tried? – user156344 Feb 19 at 16:17
  • 7
    There is the forest package, which is based on tikz. And tikz has a trees library. – user121799 Feb 19 at 16:17
3

The forest package allows you to recreate these figures.

\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={rounded corners,text=white,font=\sffamily,align=center,
grow'=east,forked edges,edge = {semithick, -stealth}, % see https://tex.stackexchange.com/a/333597/121799
anchor=west,l sep=2.5em,
if level=0{fill=green!60!black}{},
if level=1{fill=blue!70,minimum width={1.1*width("Merkmal beliebig")}}{},
if level=2{fill=blue,minimum width={1.1*width("Varianz unbekannt")}}{},
}
[Erwartungswert $\mu$
 [Merkmal\\ normalverteilt
  [Varianz bekannt]
  [Varianz unbekannt]
 ]
 [Merkmal beliebig\\ verteilt]
]
\end{forest}
\bigskip

\begin{forest}
for tree={rounded corners,text=white,font=\sffamily,align=center,
grow'=east,forked edges,edge = {semithick, -stealth}, % see https://tex.stackexchange.com/a/333597/121799
anchor=west,l sep=3.5em,
if level=0{fill=green!60!black}{},
if level=1{fill=blue!70,minimum width={1.1*width("Merkmal beliebig")}}{},
}
[Varianz $\sigma^2$
 [Merkmal\\ normalverteilt
 ]
]
\end{forest}
\end{document}

enter image description here

  • 1
    after l sep = 2.5em, i would add fork sep = 1.2em, :-). nice answer! – Zarko Feb 19 at 18:15
  • @Zarko Thanks! I agree! (The OP now knows what to do. ;-) – user121799 Feb 19 at 18:21
  • @marmot, i wonder why is needed to multiply width("...") with 1.1 that both nodes in level have equal width (or write for example as minimum width={width(" Merkmal beliebig ")}? – Zarko Feb 19 at 18:39
  • @Zarko This is not necessary, I only used one possible way of making the nodes equally wide at each level and having some grace distance on both sides. There are more sophisticated methods which I was too lazy too look up. I believe when getting exposed to forest for the first time one should not get overwhelmed with something like max(width(content)) (I just made this up but there are such options). – user121799 Feb 19 at 18:58
4

An alternative to @marmot's nice answer:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
    filv/.style={
        fill=green!50!black,
        font=\color{white},
        rectangle,
        rounded corners=3pt,
        minimum width=3.5cm
    },
    selv/.style={
        fill=cyan!50!black,
        font=\color{white},
        rectangle,
        rounded corners=3pt,
        minimum width=3.5cm,
        align=center
    },
    thlv/.style={
        fill=blue!30!black,
        font=\color{white},
        rectangle,
        rounded corners=3pt,
        minimum width=3.5cm
    }
]
\node[filv] (lv1-1) {Erwartungswert $\mu$};
\node[filv,below=2cm of lv1-1.south] (lv1-2) {Varianz $\sigma^2$};
\node[selv,above right=0.25cm and 1.5cm of lv1-1.east] (lv2-1) {Merkmal\\ normalverteilt};
\node[selv,below right=0.25cm and 1.5cm of lv1-1.east] (lv2-2) {Merkmal beliebig\\ verteilt};
\node[selv,right=1.5cm of lv1-2.east] (lv2-3) {Merkmal\\ normalverteilt};
\node[thlv,right=1.5cm of lv2-1.north east] (lv3-1) {Varianz bekannt};
\node[thlv,right=1.5cm of lv2-1.south east] (lv3-2) {Varianz unbekannt};
\draw[-latex] (lv1-2)--(lv2-3);
\coordinate[right=0.75cm of lv1-1.east] (mid1);
\coordinate[left=0.75cm of lv2-1.west] (mid1-a);
\coordinate[left=0.75cm of lv2-2.west] (mid1-b);
\draw (lv1-1)--(mid1);
\draw[latex-latex] (lv2-2)--(mid1-b)--(mid1-a)--(lv2-1);
\coordinate[right=0.75cm of lv2-1.east] (mid2);
\coordinate[left=0.75cm of lv3-1.west] (mid2-a);
\coordinate[left=0.75cm of lv3-2.west] (mid2-b);
\draw (lv2-1)--(mid2);
\draw[latex-latex] (lv3-2)--(mid2-b)--(mid2-a)--(lv3-1);
\end{tikzpicture}
\end{document}

enter image description here

4

for completness ... pure tikz version with using trees library:

\documentclass{article}
\usepackage{tikz}
 \usetikzlibrary{arrows, positioning, trees}

\begin{document}
\begin{figure}
    \tikzset{
  base/.style = {rounded corners,
                 text=white, font=\sffamily,
                 minimum width=20ex,
                 align=center},
    L1/.style = {base, fill=teal},
    L2/.style = {base, fill=cyan!80!black},
    L3/.style = {base, fill=cyan!60!black},
   grow=east,
   edge from parent fork right,
   level distance = 37mm,
   level 1/.style = {sibling distance=16mm},
   level 2/.style = {sibling distance = 8mm},
    edge from parent/.style = {draw, semithick, -latex}
            }
    \begin{tikzpicture}
\node[L1] {Erwartungswert $\mu$}
    child {node[L2] {Merkmal\\ normalverteilt}
        child {node[L3] {Varianz bekannt}}
        child {node[L3] {Varianz unbekannt}}
          }
    child {node[L2] {Merkmal beliebig\\ verteilt}}
    ;
    \end{tikzpicture}

\bigskip
    \begin{tikzpicture}
\node[L1] {Varianz $\sigma^2$}
    child {node[L2] {Merkmal\\ normalverteilt}}
   ;
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

of course, with forest is more simply and elegant solution

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.