3

I am trying to reproduce the following

enter image description here

So far I got this:

\begin{tikzpicture}[]
\small
\node[] (AB) {$A \succeq B$};
\node[]{}
    child{node[chance]{C}
      edge from parent
        node[above]{1-p}    
                }
    child{node[chance]{A} 
      edge from parent
          node[below]{p}
        };
\end{tikzpicture}

My basic problem is to label and connect simples nodes. So what is the command for "place this node A \succeq B left to the decision tree with decent distance"? Thank you very much.

  • Use tikz-cd for such jobs. – user11232 Aug 5 '15 at 14:35
3

Here are two options showing how to produce the trees using two of the most popular packages for tree generation; the first one using the forest package and the second one using tikz-qtree:

\documentclass{article}   
\usepackage{forest}
\usepackage{tikz-qtree}

\begin{document}

\[
A \succeq B
\Rightarrow
\begin{forest}
baseline,
for tree={grow=0,parent anchor=east,l sep=35pt} 
[
  [C,edge label={node[sloped,pos=0.5,below,font=\scriptsize]{$1-p$}}]
  [A,edge label={node[sloped,pos=0.5,above,font=\scriptsize]{$p$}}]
] 
\end{forest}
\succeq
\begin{forest}
baseline,
for tree={grow=0,parent anchor=east,l sep=35pt} 
[
  [C,edge label={node[sloped,pos=0.5,below,font=\scriptsize]{$1-p$}}]
  [B,edge label={node[sloped,pos=0.5,above,font=\scriptsize]{$p$}}]
] 
\end{forest}
\]

\[
A \succeq B
\Rightarrow
\begin{tikzpicture}[baseline,grow=right,level distance=35pt]
\Tree[
  \edge node[sloped,pos=0.5,below,font=\scriptsize]{$1-p$}; C
  \edge node[sloped,pos=0.5,above,font=\scriptsize]{$p$}; A
] 
\end{tikzpicture}
\succeq
\begin{tikzpicture}[baseline,grow=right,level distance=35pt]
\Tree[
  \edge node[sloped,pos=0.5,below,font=\scriptsize]{$1-p$}; C
  \edge node[sloped,pos=0.5,above,font=\scriptsize]{$p$}; B
] 
\end{tikzpicture}
\]

\end{document}

The result:

enter image description here

  • The code looks simple. But it gives me fatal errors, I cannot compile. Are there known package-clashes to forest? I use some other tikz-pictures in my code. – Mac Aug 5 '15 at 14:53
  • @Mac As a first step, please compile just my code (with no additions, in a simple test document). Does it give you errors? And if so, which ones exactly. – Gonzalo Medina Aug 5 '15 at 14:55
  • Ah ok, even MWE doesnt work. It's again some problem with package- loading. It says "forest.sty not found"... I'm working on it ... package manager says in turn: too many requests from my IP ... so there is a delay in testing your approach, which is certainly fine. So thanks anyway :) – Mac Aug 5 '15 at 14:58
  • @Mac I see, so the forest package isn't installed in your system. Once you've installed it, the code should work with no problems. I could also give an alternative using tikz-qtree if you want to. – Gonzalo Medina Aug 5 '15 at 15:04
  • @Mac In the meantime I updated my answer with an option using tikz-qtree. – Gonzalo Medina Aug 5 '15 at 15:22
2

As Mr. Kumar says, I would go with . The symbol declaration is a bit of an over-kill here, but you may use it in other graphs as well even for vertical and diagonal arrows.

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\tikzset{%
    symbol/.style={%
        draw=none,
        every to/.append style={%
            edge node={node [sloped, allow upside down, auto=false]{$#1$}}}
    }
}

\begin{document}
\[
\begin{tikzcd}[every label/.append style={sloped}, row sep=tiny] % or small
& & & A & & B\\
A  \arrow[symbol={\succeq}]{r} & B \arrow[Rightarrow]{r} & \null\arrow[start anchor=center, dash]{ur}[above]{p}\arrow[start anchor=center,dash]{dr}[below]{1-p} & \arrow[symbol={\succeq}]{r} & \null\arrow[start anchor=center, dash]{ur}[above]{p}\arrow[start anchor=center,dash]{dr}[below]{1-p} & \\
& & & C & & D
\end{tikzcd}
\]
\end{document} 

enter image description here

If you want a more consistent spacing, you might want to add the \Rightarrow as a symbol as well.

\arrow[symbol=\Rightarrow]{r}

enter image description here

If you want to get tighter horizontal spacing, you can define each & of the first line to any value you like. E.g. &[-3ex] & & A & & B\\ might look good.

Another possibility would be to write the first part as a normal formula. Delete the first & from the first and last line and start the second one with A \succeq B \arrow[Rightarrow]{r}.

  • For simple trees like the one in the image, tikz-cd could be an option but for larger trees, perhaps I wouldn't use it. – Gonzalo Medina Aug 5 '15 at 14:51
  • @GonzaloMedina For sure. That's true. – LaRiFaRi Aug 5 '15 at 14:51
  • I can't neither compile this. Obviously I use several forbitten package-combinations ... what could be the most likely reason? – Mac Aug 5 '15 at 14:55
  • @Mac no idea. I can't guess. Begin with my example and add piece by piece of what you want to have as well. You will find the problem in about 5 minutes then... – LaRiFaRi Aug 5 '15 at 14:57
  • I managed to install the required package. How can I adjust the overall size in zikt-cd environment? The result looks too small :) – Mac Aug 7 '15 at 7:46

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.