1

Could any help me with how i'd get the into my latex presentation for class i've done all the work but i have no idea how to get this probability tree into latex, especially with the general probabilities as it goes p timesenter image description here

  • You mean how to write math expression in latex? I know that you can design probability trees by using trees package. However, I haven't use it – Yorgos Dec 12 '16 at 12:57
  • 1
    Or something like this : texample.net/tikz/examples/probability-tree ? – ebosi Dec 12 '16 at 12:58
  • Welcome! What have you tried? Can you provide the content, even if not the format, as TeX code? Also, please clarify what exactly you want to typeset or draw. Right now, that's really not very clear. – cfr Dec 12 '16 at 22:38
5

First Caveat

Note that I think I ought not answer do-it-for-mes, although I and others sometimes do. However, I like trees and it is, after all, your first question.

However, since I answer do-it-for-mes solely for me, I am sympathetic to requests for adjustments, refinements, corrections and explanations only if I find them especially appealing. Generally, an answer to a do-it-for-me from me is provided 'as is'. If it answers your question, you're in luck and got somebody to do your work for you. If not, tough. I was answering it only for me, so if it suits my purposes, that's all that matters.


Second Caveat

I answered this to practise using the latest version of Forest. As such, the code's raison d'être is to utilise features newly available in version 2.1. It follows that the code will not work with earlier versions of Forest. If you wish to use it, you must update your TeX installation and ensure it provides version 2.1. Alternatively, you may consult the manual for the version you do have and replace the new code with equivalents supported also in earlier versions.

If this was not a do-it-for-me, I would try to respond to a request for a version compatible with an earlier version of Forest. However, it is, so I probably wouldn't.


[Edited in light of Sašo's suggestions at http://chat.stackexchange.com/transcript/message/34121933#34121933, http://chat.stackexchange.com/transcript/message/34125683#34125683 and http://chat.stackexchange.com/transcript/message/34150084#34150084, though not always in accordance with them.]

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{forest}
\begin{document}
\forestset{
  declare toks={iteration}{},
  declare boolean={is auto iteration}{0},
}
\begin{forest}
  label my edge/.style n args=3{% based on Sašo's suggestion: http://chat.stackexchange.com/transcript/message/34121933#34121933
    edge label={node [font=\scriptsize, #3] {$\frac{#1}{#2}$}}
  },
  /tikz/put left/.style={anchor=north east, pos=.6, left, xshift=-3.5pt},
  /tikz/put below/.style={midway, below},
  for tree={
    math content,
    grow'=0,
    % Sašo: http://chat.stackexchange.com/transcript/message/34121933#34121933
    calign primary angle=0,
    calign secondary angle=30,
    calign=fixed edge angles,
    delay={
      if iteration={}{iteration/.option=level, is auto iteration}{},
    },
  },
  before typesetting nodes={% edited in light of Sašo's suggestions: http://chat.stackexchange.com/transcript/message/34125683#34125683 (though not entirely in accordance with them)
    for tree={
      if n=1{
        if content={}{
          content/.process={Ow}{iteration}{\strut w_{#1}},
          anchor=mid,
          if is auto iteration={
            if iteration=1{
              label my edge={2}{n}{put left},
            }{
              label my edge/.process={Ow+nw}{iteration}{#1-1}{{2}{n-#1}{put left}},
              if phantom={}{
                !u.label my edge/.process={OW+nw2}{iteration}{#1-2}{{n-#1}{n-#2}{put below}},
              },
            },
          }{
            label my edge/.process={Ow}{iteration}{{2}{n-#1}{put left}},
            !u.label my edge/.process={Ow}{iteration}{{n-#1}{n-#1-2}{put below}},
          },
        }{},
      }{
        coordinate,
      }
    }
  },
  !rLs.before computing xy={% Sašo: http://chat.stackexchange.com/transcript/message/34150084#34150084
    l/.option=!r1.l,
    s/.option=!r1.s,
  },
  [
    []
    [
      []
      [
        []
        [
          []
          [
            []
            [, edge={dotted}
              [, phantom]
              [, edge={dotted}
                [, iteration=p]
                [, phantom]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

Forest tree

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.