3

I've got: enter image description here I'd like something like: enter image description here

Code:

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

\begin{document}
\begin{forest}
for tree={rectangle,rounded corners,draw, l sep=20pt,
    if n children=0{
        tier=terminal
    }{}}
[Initial State 
    [No Failures,edge label={node[midway,left] {$0.9994$}} [OK,green,edge label={node[midway,left] {$1$}}]]
    [Failure,edge label={node[midway,right] {$0.0006$}}
        [A,edge label={node[midway,left] {\small$5\cdot 10^{-4}$}}[OK,green,edge label={node[midway,left] {$0.95$}}]]
        [B,edge label={node[midway,right,yshift=-1.5mm,xshift=-0.4mm] {\small$8\cdot 10^{-5}$}}[OK,green,edge label={node[midway,left] {$0.9$}}]] 
        [C,edge label={node[midway,right,xshift=2mm] {\small$2\cdot 10^{-5}$}}
            [OK,green, edge label={node[midway,right,yshift=-5mm] {$0.4$}}]
            [1, edge label={node[midway,left] {$0.3$}}
                 [FAIL, red]]
            [2, edge label={node[midway,right] {$0.3$}}
                 [FAIL, red]]               
        ]
    ] 
]
\end{forest}
\end{document}

Has anyone got a solution?

3

Something like this?

\documentclass{article}
\usepackage{forest}
\forestset{special edge/.style={        edge path={
            \noexpand\path[\forestoption{edge}]
            let \noexpand\p1=(!u.parent anchor), 
            \noexpand\p2=(.child anchor) in (!u.parent anchor) -- 
            (\noexpand\x2,{\noexpand\y1-abs(\noexpand\x2-\noexpand\x1)}) 
    --   (.child anchor)\forestoption{edge label};
        },      
}}
\begin{document}
\begin{forest}
for tree={rectangle,rounded corners,draw, l sep=20pt,
    if n children=0{
        tier=terminal,
    }{}}
[Initial State 
    [No Failures,edge label={node[midway,left] {$0.9994$}} [OK,green,edge label={node[midway,left] {$1$}}]]
    [Failure,edge label={node[midway,right] {$0.0006$}}
        [A,edge label={node[midway,left] {\small$5\cdot 10^{-4}$}}[OK,green,edge label={node[midway,left] {$0.95$}}]]
        [B,edge label={node[midway,right,yshift=-1.5mm,xshift=-0.4mm] {\small$8\cdot 10^{-5}$}}[OK,green,edge label={node[midway,left] {$0.9$}}]] 
        [C,edge label={node[midway,right,xshift=2mm] {\small$2\cdot 10^{-5}$}}
            [OK,special edge,green, edge label={node[pos=0,above left] {$0.4$}}]
            [1, edge label={node[midway,right] {$0.3$}}
                 [FAIL, red]]
            [2, edge label={node[midway,right] {$0.3$}}
                 [FAIL, red]]               
        ]
    ] 
]
\end{forest}
\end{document}

enter image description here

In order to get rid of the gaps, you may want to use

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shapes.misc}
\forestset{special edge/.style={        edge path={
            \noexpand\path[\forestoption{edge}]
            let \noexpand\p1=(!u.parent anchor), 
            \noexpand\p2=(.child anchor) in (!u.parent anchor) -- 
            (\noexpand\x2,{\noexpand\y1-abs(\noexpand\x2-\noexpand\x1)}) 
    --   (.child anchor)\forestoption{edge label};
        },      
}}
\begin{document}
\begin{forest}
for tree={rounded rectangle,draw, l sep=20pt,
    if n children=0{
        tier=terminal,
    }{}}
[Initial State 
    [No Failures,edge label={node[midway,left] {$0.9994$}} [OK,green,edge label={node[midway,left] {$1$}}]]
    [Failure,edge label={node[midway,right] {$0.0006$}}
        [A,edge label={node[midway,left] {\small$5\cdot 10^{-4}$}}[OK,green,edge label={node[midway,left] {$0.95$}}]]
        [B,edge label={node[midway,right,yshift=-1.5mm,xshift=-0.4mm] {\small$8\cdot 10^{-5}$}}[OK,green,edge label={node[midway,left] {$0.9$}}]] 
        [C,edge label={node[midway,right,xshift=2mm] {\small$2\cdot 10^{-5}$}}
            [OK,special edge,green, edge label={node[pos=0,above left] {$0.4$}}]
            [1, edge label={node[midway,right] {$0.3$}}
                 [FAIL, red]]
            [2, edge label={node[midway,right] {$0.3$}}
                 [FAIL, red]]               
        ]
    ] 
]
\end{forest}
\end{document}

enter image description here

  • Great, only that I need the child anchor shifted a bit to the left, since the edge to "1" is a bit left to u.south, could you help me with that? I tried manually offsetting the variable by a few mm, but it doesn't work... – Horst Monika Jan 26 at 19:19
  • @HorstMonika I slightly changed gears and now added a special edge style for that. (BTW, are the gaps at the rounded corners on purpose? If not, you may want to load \usetikzlibrary{shapes.misc} and use rounded rectangle instead of rectangle,rounded corners.) – marmot Jan 26 at 21:21
  • I used your (edited) solution. Thank you very much! – Horst Monika Jan 27 at 13:47

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.