2

How do I insert Yes and No beside the solid arrows?

I tried putting node [near end, right] {Yes} after each node and child declaration but this just messes up the flow of the decision tree.

Code

    \noindent
    \begin{figure}[htbp]
      \centering 
      \sffamily

      \tikzstyle{level 1}=[level distance=1.5cm, sibling distance=4.25cm]
      \tikzstyle{level 2}=[level distance=1.5cm, sibling distance=2.25cm]
      \tikzstyle{level 3}=[level distance=1.5cm, sibling distance=4.25cm]
      \tikzstyle{level 4}=[level distance=1.5cm, sibling distance=2.25cm]

      \tikzset{decision/.style={
        draw=gray-5-border, solid, fill=gray-e-bg, rectangle, 
        anchor=north,
        inner sep=2mm, outer sep=0, text centered, growth parent anchor=south} 
      }
      \tikzset{prediction/.style={
        draw=gray-4-border, solid, fill=gray-d-bg, ellipse, 
        anchor=north,
        inner sep=2mm, outer sep=0, text centered, growth parent anchor=south} 
      }
      \tikzset{arrow/.style={-latex, thick}}
      \tikzset{arrow-dashed/.style={-latex, dashed, thick}}

      \begin{tikzpicture}
        \node [prediction] {+0.5} [dashed, -latex, thick, ->]
          child { 
            node [decision] {$a < 4.5$} [->]
              child {
                node [prediction] {-0.7} [solid, -latex, thick, ->] 
                  child {
                    node [decision] {$b > 1$} [dashed, -latex, thick, ->]
                      child {
                        node [prediction] {+0.4} [solid, -latex, thick, ->]
                      }
                      child {
                        node [prediction] {-0.2} [solid, -latex, thick, ->]
                      }
                  }
                  child {
                    node [decision] {$a > 2$} [dashed, -latex, thick, ->]
                      child {
                        node [prediction] {-0.1} [solid, -latex, thick, ->]
                      }
                      child {
                        node [prediction] {+0.1} [solid, -latex, thick, ->]
                      }
                  }
              }
              child {
                node [prediction] {+0.2} [solid, -latex, thick, ->]
              }
          }
          child {
            node [decision] {$b > 0$}
              child {
                node [prediction] {+0.3} [solid, -latex, thick, ->]
              }
              child {
                node [prediction] {-0.6} [solid, -latex, thick, ->]
              }
          }
        ;
      \end{tikzpicture}

      \caption{A diagram of Freund and Mason's general alternating decision tree}
      \label{fig:diagram-adt}
    \end{figure}

Output

enter image description here

  • 1
    Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – Qrrbrbirlbel Oct 3 '13 at 17:34
  • 2
    You need to use node [prediction {$-0.7$} edge from parent [dashed, -latex, thick] node [near end, right] {Yes}. Note that I also have used math-mode for -0.7 so that the minus sign will be typeset correct. I also removed -> because you already had -latex in there, the -> will overwrite the -latex with -to. And please use the edge from parent style to include at least -latex, thick so you don’t need to repeat that everytime. – Qrrbrbirlbel Oct 3 '13 at 17:37
  • @Qrrbrbirlbel - thank you very much. I am genuinely sorry and I will take note of that next time I ask a question here. I was able to apply your solution but what happened is the two child nodes' arrows were misplaced and these arrows are now directed south of the newly added {Yes} node. How do I solve this? – Saggy Manatee And Swan Folk Oct 3 '13 at 18:00
  • I just used node [near start, right, yshift=0.25cm] {Y} node [prediction] {$-0.7$} edge from parent [solid, -latex, thick]. – Saggy Manatee And Swan Folk Oct 3 '13 at 18:04
  • @Qrrbrbirlbel: will there be an upvoted answer for this problem? This is not an unanswered question, but it is indeed listed as one... – masu Oct 8 '13 at 18:50
1

You need to use

node [prediction {$-0.7$} edge from parent [dashed] node [near end, right] {Yes}

I’d also add -latex, thick to the edge from parent so that you don’t have to repeat common options every time.

I also removed -> from the options because you already had -latex in there, the -> will overwrite the -latex´ with-to(or to whatever>` is set).

Note that I also have used math-mode for -0.7 so that the minus sign will be typeset correctly (it is advisory to use text depth=+0pt for the nodes because the minus sign adds a certain depth, but so does the +).

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.