4

I am asking myself if I can create a picture like the one presented hereunder with TikZ:

enter image description here

Edit: This is what I have tried so far. I really want to include brackets as in the original tree shown above.

    \begin{document}
    \begin{tikzpicture}
      [
        grow                    = right,
        sibling distance        = 6em,
        level distance          = 10em,
        edge from parent/.style = {draw, -latex},
        every node/.style       = {font=\footnotesize},
        sloped
      ]
      \node [root] {$\textbf{x}$: \textbf{status quo}}
        child { node [env] {\color{red}{$\textbf{x}$ \textbf{is}}\\ \color{red}{\textbf{chosen}}}
          edge from parent node [below] {\textbf{No objection}} }
        child { node [dummy] {\textbf{\color{blue}{Option y}}}
          child { node [dummy] {\color{red}{$\textbf{S}$' \textbf{actions}}: \\\color{blue}{\textbf{withdraws}} or\\\color{blue}{ \textbf{maintains}}}
            child { node [env] {\textbf{\color{blue}{Option y}}}
            child { node [env] {\color{red}{$\textbf{z}$ \textbf{is chosen}}}
              edge from parent node [above] {\textbf{counterob.}}
                               node [below] {\textbf{by} $\textbf{T}$} }
                               child { node [env] {\color{red}{$\textbf{y}$ \textbf{chosen}}}
              edge from parent node [above] {\textbf{No counter-}}
                               node [below] {\textbf{objection}} }
              edge from parent node [below] {\textbf{Maintains}} }
                       child { node [env] {\color{red}{$\textbf{x}$ \textbf{is}} \\ \color{red}{\textbf{chosen}}}
                    edge from parent node [above] {\textbf{Withdraws}} }
            edge from parent node [below] {\textbf{oppose} \textbf{y}} }
          child { node [env] {\color{red}{\textbf{y} \textbf{is chosen}}}
                  edge from parent node [above, align=center]
                    {\textbf{No}\\ \textbf{opposition}\\\textbf{against} \textbf{y}}}
                  edge from parent node [above] {$\textbf{S}$ \textbf{Objects}} };
    \end{tikzpicture}
\end{document}
JBT
  • 97
  • 5
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow Nov 07 '16 at 20:13
  • 4
    Rather than posting code fragments please post a complete minimal working example. In particular, the code should compile. –  Nov 07 '16 at 21:58

2 Answers2

6

enter image description here

I'm not sure, if correct guess what you like to obtain. In your code (after adding missing definition) grow to right ...

\documentclass[tikz, border=3mm, preview]{standalone}
\usetikzlibrary{decorations,
                calligraphy,
                }
\begin{document}
\begin{tikzpicture}[
Brace/.style = {decorate,
        decoration={calligraphic brace, mirror,
        pre =moveto, pre  length=1pt,
        post=moveto, post length=1pt,
        raise=3pt, amplitude=6pt},
        thick, pen colour={red}
                },
every node/.style = {font=\footnotesize\bfseries\itshape, align=center},
      root/.style = {font=\sffamily\bfseries,text=teal},
    redtxt/.style = {text=red},
   bluetxt/.style = {font=\footnotesize\bfseries\itshape\color{blue}},
% tree options
    grow                    = down,
    sibling distance        = 9em,
    level distance          = 9em,
    edge from parent/.style = {draw, -latex, sloped, auto=above, anchor=south},
                    ]
\node (root) [root] {x status quo}
    child { node (x) [redtxt] {x is chosen}
      edge from parent node {No objection} }
    child { node     [bluetxt] {Option y}
          child { node [bluetxt] {\textvolor{red}{S'} actions: \\ withdraws or\\ maintains}
            child { node (y) [bluetxt] {Option y}
            child { node (z) [redtxt] {z is chosen}
              edge from parent node  {counterob.\\ by T} }
                       child { node [redtxt] {y is chosen}
              edge from parent node {No counter-\\ objection} }
              edge from parent node {Maintains} }
                       child { node [redtxt] {x is chosen}
                    edge from parent node {Withdraws} }
            edge from parent node [above] {oppose y} }
          child { node [redtxt] {y is chosen}
                  edge from parent node {No\\ opposition\\ againsty}}
                  edge from parent node {S Objects} };
%              
\draw[Brace] (root.north -| z.west) -- 
    node[left=12pt] {Stage 1:\\ bla bla bla bla} (x -| z.west);
\draw[Brace] (x -| z.west) -- 
    node[left=12pt] {Stage 2:\\ bla bla bla bla} (y -| z.west);
\draw[Brace] (y -| z.west) --
    node[left=12pt] {Stage 3:\\ bla bla bla bla} (z.west);
\end{tikzpicture}
\end{document}

As you can see from code, I made lot of simplification in xour code: all \texbf{...} are deleted since in every node styler I add font=\bfseries\itshape, also I rename node styles that reflect nodes text color. For braces the fancy TikZ library calligraphy, is selected. All edge labels are placed above edges.

Edit: IN your code you have two color text in node child { node [bluetxt] {S' actions: \\ withdraws or\\ maintains} which I was in the first version of answer not able to solve with used approach. With help of @cfr (see comments to question Coloring-text-in-tree-nodes) I resolve problem with this bug (see comments to question How to apply colour options to the contents of TikZ nodes ... ?) and now accordingly change above MWE.

Zarko
  • 296,517
  • @JBT, see edit of mine answer. Now is resolved issues of two color text in tree nodes if one color is set globally (not addressed in the first version of answer). – Zarko Nov 08 '16 at 01:26
  • I am ok with your first answer. Thks. – JBT Nov 08 '16 at 01:38
5

This is an adaption of Zarko's answer using Forest, which makes it possible to specify the tree much more concisely and to automate a good deal of the formatting. If this is a one-off diagram, this solution will probably hold little interest. If, however, you need to do multiple trees, it is worth learning Forest or tikz-qtree for the benefit of the succinct syntax. Forest is the more powerful and supports a good deal of automation, making it easy to style trees flexibly and consistently. (That is, I'm a fan.)

In Forest, for example, after setting up the tree for our desired look, we can simply write

  [x status quo
    [x is chosen, my label=No objection]
    [Option y, my label=S Objects
      [S' actions:\\withdraws or\\maintains, my label=oppose y
        [Option y, my label=Maintains
          [z is chosen, my label=counterob.\\by T]
          [y chosen, my label=No\\opposition\\against y]
        ]
        [x is chosen, my label=Withdraws]
      ]
      [y is chosen, my label=No counter-\\objection]
    ]
  ]

to create the main part of the tree sans stage labels on the left. The stage labels are added using a simple \foreach loop:

  before typesetting nodes={
    tikz+={
      \coordinate (c) at (current bounding box.west);
      \foreach \i/\j/\k [count=\n] in {!r.north/!r1.south/{(y,S): objection against x},!r1.south/!r211.north/Right to opposition,!r211.north/!r2111.south/Counter-objection by T}
      \draw [draw=blue!50!cyan, thick, decorate, decoration={brace, mirror, amplitude=5pt}] ([yshift=-1.5pt]c |- \i) -- ([yshift=1.5pt]c |- \j) node [midway, left, font=\bfseries\itshape, align=center, xshift=-15pt] {\textcolor{red}{Stage \n:}\\\k};
    }
  }

The result looks like this:

Forest solution

This really has too many colours. I did this partly to make it easy to see where the colouring is being added. Obviously, it can be adjusted to suit.

Complete code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing,arrows.meta}
\begin{document}
\begin{forest}
  circle here/.style={
    tikz+={
      \path [fill=teal] ([yshift=-1.5pt].parent anchor) circle (1.5pt);
    },
  },
  for tree={
    align=center,
    if level=0{
      font=\bfseries,
      text=teal,
      circle here,
    }{
      font=\bfseries\itshape,
      if n children=0{
        text=red,
      }{
        text=blue,
        circle here,
      },
    },
    l sep'+=80pt,
    s sep'+=20pt,
    edge={-Latex, draw=teal},
    parent anchor=children,
  },
  my label/.style={
    edge label={node [midway, sloped, font=\bfseries\itshape, align=center, above] {#1}}
  },
  before typesetting nodes={
    tikz+={
      \coordinate (c) at (current bounding box.west);
      \foreach \i/\j/\k [count=\n] in {!r.north/!r1.south/{(y,S): objection against x},!r1.south/!r211.north/Right to opposition,!r211.north/!r2111.south/Counter-objection by T}
      \draw [draw=blue!50!cyan, thick, decorate, decoration={brace, mirror, amplitude=5pt}] ([yshift=-1.5pt]c |- \i) -- ([yshift=1.5pt]c |- \j) node [midway, left, font=\bfseries\itshape, align=center, xshift=-15pt] {\textcolor{red}{Stage \n:}\\\k};
    }
  }
  [x status quo
    [x is chosen, my label=No objection]
    [Option y, my label=S Objects
      [S' actions:\\withdraws or\\maintains, my label=oppose y
        [Option y, my label=Maintains
          [z is chosen, my label=counterob.\\by T]
          [y chosen, my label=No\\opposition\\against y]
        ]
        [x is chosen, my label=Withdraws]
      ]
      [y is chosen, my label=No counter-\\objection]
    ]
  ]
\end{forest}
\end{document}
cfr
  • 198,882
  • This answer is also well received. I was wondering in what way could the height of the graph be reduced in order to make it fit in a beamer format. Thanks for your outcomes. – JBT Nov 08 '16 at 19:18
  • Where I've written l sep'+=80pt, try making 80 smaller. Where I've written s sep'+=20pt, try making 20 bigger. The first gives the minimum distance between levels, so is increasing vertical spread. The second gives the minimum distance between siblings, so is increasing the horizontal spread. What you want to do is make it a bit wider and a bit shorter. Does that help? – cfr Nov 08 '16 at 21:42