0

I have this tree:

% Decision tree
% Author: Stefan Kottwitz
% https://www.packtpub.com/hardware-and-creative/latex-cookbook
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\tikzset{
  treenode/.style = {shape=rectangle, draw},
  dec/.style={shape=rectangle,draw,fill=blue},
  chance/.style={shape=circle,draw,fill=red},
  end/.style={shape=rectangle}
}
\begin{document}
\begin{tikzpicture}
  [
    grow                    = right,
    sibling distance        = 7em,
    level distance          = 12em,
    edge from parent/.style = {draw, -latex},
    every node/.style       = {font=\footnotesize},
    sloped
  ]
  \node [dec] {}
    child { node [chance, label=below:\$3] {} 
      edge from parent node [below] {L} }
    child { node [chance, label=below:\$8] {} 
      child { node [end] {\$8} 
        edge from parent node [above] {HD} } 
      child { node [end] {\$8}
              edge from parent node [above, align=center] {LD} }
              edge from parent node [above] {S} } %comes from root
      child { node [chance, label=below:\$1] {}
        edge from parent node [above] {M} } ;
\end{tikzpicture}
\end{document}

The picture currently looks like this:

enter image description here

I would like to "double cross out" the edge from the blue square to the top red circle (that is, put two short lines through the edge, perpendicular to the edge). The two lines should be between "M" and the red circle.

How can I do this in tikz?

3
  • I have tried: tex.stackexchange.com/questions/31453/… But I can't use strike out in this type of setup, it seems. Nov 27 '19 at 15:17
  • One could create a [double strike] shape, although you mgiht want to set [minimum width] to something more than 2 [inner sep]. Nov 27 '19 at 15:46
  • Hi @JohnKormylo, could you please elaborate on that and include code in an answer? Nov 27 '19 at 15:56
1

On second thought, just use two [strike out]s.

Note, the size of the strike out is determined by the contents (text), or use [minimum width] and [minimum height].

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\tikzset{
  treenode/.style = {shape=rectangle, draw},
  dec/.style={shape=rectangle,draw,fill=blue},
  chance/.style={shape=circle,draw,fill=red},
  end/.style={shape=rectangle}
}
\begin{document}
\begin{tikzpicture}
  [
    grow                    = right,
    sibling distance        = 7em,
    level distance          = 12em,
    edge from parent/.style = {draw, -latex},
    every node/.style       = {font=\footnotesize},
    sloped
  ]
  \node [dec] (AA){}
    child { node [chance, label=below:\$3] {} 
      edge from parent node [below] {L} }
    child { node [chance, label=below:\$8] {} 
      child { node [end] {\$8} 
        edge from parent node [above] {HD} } 
      child { node [end] {\$8}
              edge from parent node [above, align=center] {LD} }
              edge from parent node [above] {S} } %comes from root
      child { node (BB) [chance, label=below:\$1] {}
        edge from parent node [above] {M} } ;
  \path (AA) -- (BB) node[draw,strike out, pos=0.2] {}
                     node[draw,strike out, pos=0.25] {};
\end{tikzpicture}
\end{document}

demo


This version creates a [double strike] shape.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\tikzset{
  treenode/.style = {shape=rectangle, draw},
  dec/.style={shape=rectangle,draw,fill=blue},
  chance/.style={shape=circle,draw,fill=red},
  end/.style={shape=rectangle}
}
\makeatletter
\pgfdeclareshape{double strike}
{%
  \inheritsavedanchors[from=rectangle]% % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]%
  \inheritanchor[from=rectangle]{north}%
  \inheritanchor[from=rectangle]{north west}%
  \inheritanchor[from=rectangle]{north east}%
  \inheritanchor[from=rectangle]{center}%
  \inheritanchor[from=rectangle]{west}%
  \inheritanchor[from=rectangle]{east}%
  \inheritanchor[from=rectangle]{mid}%
  \inheritanchor[from=rectangle]{mid west}%
  \inheritanchor[from=rectangle]{mid east}%
  \inheritanchor[from=rectangle]{base}%
  \inheritanchor[from=rectangle]{base west}%
  \inheritanchor[from=rectangle]{base east}%
  \inheritanchor[from=rectangle]{south}%
  \inheritanchor[from=rectangle]{south west}%
  \inheritanchor[from=rectangle]{south east}%
  \foregroundpath{
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\southwest}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@yb}}
    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@ya}}
    \pgfpathlineto{\northeast}
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{}
 }%
}%
\makeatother
\begin{document}
\begin{tikzpicture}
  [
    grow                    = right,
    sibling distance        = 7em,
    level distance          = 12em,
    edge from parent/.style = {draw, -latex},
    every node/.style       = {font=\footnotesize},
    sloped
  ]
  \node [dec] (AA){}
    child { node [chance, label=below:\$3] {} 
      edge from parent node [below] {L} }
    child { node [chance, label=below:\$8] {} 
      child { node [end] {\$8} 
        edge from parent node [above] {HD} } 
      child { node [end] {\$8}
              edge from parent node [above, align=center] {LD} }
              edge from parent node [above] {S} } %comes from root
      child { node (BB) [chance, label=below:\$1] {}
        edge from parent node [above] {M} } ;
  \path (AA) -- (BB) node[draw, double strike, pos=0.25] {};
\end{tikzpicture}
\end{document}
2
  • would it be okay to use--\draw (1,0.5) node{} -- (1.1,.7); \draw (1.1,0.5) node{} -- (1.2,.7); --or some such
    – js bibra
    Nov 27 '19 at 16:13
  • @jsbibra - Seems like a lot of trial and error, but it is up to you. Nov 27 '19 at 16:20

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.