[Tex/LaTex] Decision trees in Tikz

tikz-trees

So I can do this:

tree one

But I want to do this:
tree two

That is, its easy to add text alongside the connectors (either slanting alongside them or straight), but I would like part of the connector to be flat with the caption text along the flat part for better readability.

I thought perhaps I could do this by creating a fake node that would be just a line with text above it. Not sure how to implement that or if there is an easier way.

Thanks for any ideas?

Code for first figure:

\documentclass{article} 
\usepackage{tikz}
\begin{document}

\tikzstyle{decision} = [rectangle, minimum height=18pt, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{chance} = [circle, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{line} = [draw=none]

\tikzset{
grow=right,
sloped,
join=miter,
level 1/.style={sibling distance=5cm,level distance=5.2cm},
level 2/.style={sibling distance=4cm, level distance=6.7cm},
level 3/.style={sibling distance=3cm, level distance=6.7cm},
edge from parent/.style={ultra thick, draw=blue},
edge from parent path={(\tikzparentnode.east) -- (\tikzchildnode.west)},
every node/.style={text ragged, inner sep=1mm}
}

\begin{tikzpicture}[]
\small
\node[decision]{}
    child{node[line]{}
      edge from parent
        node[above]{Option 2}
    }
    child{node[chance]{}
      child{node[line]{}}
      child{node[line]{}}
      edge from parent
            node[below]{Option 1}
        };
\end{tikzpicture}

\end{document}  

Best Answer

You can use the forest package. A little example (adjust the settings according to your needs):

\documentclass{article}
\usepackage{forest}

\tikzset{
Above/.style={
  midway,
  above,
  font=\scriptsize,
  text width=1.5cm,
  align=center,
  },
Below/.style={
  midway,
  below,
  font=\scriptsize,
  text width=1.5cm,
  align=center
  }
}

\begin{document}

\begin{forest} 
for tree={
  grow=east,
  draw=cyan,
  circle,
  line width=0.2pt,
  parent anchor=east,
  child anchor=west,
  edge={draw=cyan},
  edge label={\Huge\color{black}},
  edge path={
    \noexpand\path[\forestoption{edge}]
      (!u.parent anchor) -- ([xshift=-1.6cm].child anchor) --    
      (.child anchor)\forestoption{edge label};
  },
  l sep=2cm,
} 
[,rectangle, s sep=35pt,
  [,edge label={node[Below]{option1}}
    [,edge label={node[Below]{a longer text goes here}}
    ]
    [,edge label={node[Above]{text}}
    ]
  ]
  [,edge label={node[Above]{option2}}
    [,edge label={node[Below]{a longer text goes here}}
    ]
    [,edge label={node[Above]{text}}
    ]
  ]
]
\end{forest}

\end{document}

enter image description here

Related Question