On 31.03.2018 00:35, Scott Kostyshak wrote:
I would like to make a simple tree that uses math. The current way I do
it is to use the linguistics module, which gives access to the forest
package. Then I go to Insert > custom insets > Structure tree. I then
wrap the math I want to write in \protect. Attached is an example of
what I'm currently doing. It works, but I don't like writing out
\protect, and I have the feeling I'm asking the forest package to do
something it was not meant to do (include math).

Does someone recommend a different way?

I was in need of a decision tree diagram and found it rather hard to get a satisfactory result. Maybe something of this is helpful to you.

In the preamble:

\forestset{
  declare toks={elo}{},
    my label/.style={
        edge label={node[midway,above,text width=1.7cm,align=left]{#1}}
    },
    decision tree/.style={
    for tree={
        grow=east,
        minimum size=2pt,
        inner sep=2pt,
        parent anchor=east,
        child anchor=west,
        l sep+=20mm,
        s sep+=3mm,
edge path'={(!u.parent anchor) -- ([xshift=-18mm].child anchor)\forestove{elo} -- (.child anchor)},
    }
    }
}

An example diagram (I added an instant preview around it):

{\small
\begin{forest} decision tree
    [,label=$n_0$,draw
      [,label=$n_3$,draw ,my label={$s_5,s_6$}
        [$o_6$, my label=$s_6(n_3)$]
        [$o_5$, my label=$s_5(n_3)$]
      ]
      [,label=$n_2$,draw, my label={$s_3,s_4$}
        [$o_4$, my label=$s_4(n_2)$]
        [$o_3$, my label=$s_3(n_2)$]
      ]
      [,label=$n_1$,draw, my label={$s_1,s_2$}
        [$o_2$, my label=$s_2(n_1)$]
        [$o_1$, my label=$s_1(n_1)$]
      ]
    ]
\end{forest}}

Reply via email to