4

I would like to prune (for indication) some branches of this minimax tree. I'd like to have a cross line over each branch that would be pruned in the final tree. I cannot seem to be able to do it with synttree package in an obvious way. Can somebody suggest an elegant way to do that?

A minimal working example of the tree that I'd like some of its leaves pruned is the following:

\documentclass[10pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{subfig}
\usepackage[latin1]{inputenc}                           % Input encoding
\usepackage{amsmath}                                    % Math
\usepackage{empheq}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{synttree}

\begin{document}

\begin{figure}[h]
\centering
\scalebox{0.8}
{
\branchheight{0.4in}
\childsidesep{1em}
\childattachsep{0.1in}
\synttree
[$\nabla$
    [$\triangle$
        [$\nabla$
            [5]
            [1]
            [4]
        ]
        [$\nabla$
            [2]
            [7]
            [9]
        ]
        [$\nabla$
            [3]
            [5]
            [7]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [10]
            [2]
            [1]
        ]
        [$\nabla$
            [5]
            [1]
            [4]
        ]
        [$\nabla$
            [8]
            [9]
            [2]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [3]
            [1]
            [2]
        ]
        [$\nabla$
            [7]
            [6]
            [5]
        ]
        [$\nabla$
            [9]
            [8]
            [9]
        ]
    ]
]
}
\caption{Minimax tree}
\end{figure}
\end{document}
  • 3
    I can think of several visual outcomes that might all be called "pruning". Can you be more specific on what the end result should look like? – Steven B. Segletes Apr 30 '14 at 23:46
  • for example this one with either 2-line or 1-line cuts across the branches to be pruned. Hope this clarified what my expected visual outcome would be. – jtimz May 1 '14 at 14:18
3

If you are willing to switch to the powerful forest package (the syntax is really similar), you will have access to the full power of TikZ, besides the nice features provided by the package. You can then use a decoration for defining s style to be easily applied to the desired edges; a little example:

\documentclass[10pt,a4paper]{article}
\usepackage{forest}
\usetikzlibrary{decorations.markings}

\newsavebox\mybox
\savebox\mybox{%
  \tikz{
    \draw[ultra thick,red] (-4pt,-4pt) -- (4pt,4pt);
    \draw[ultra thick,red] (-4pt,4pt) -- (4pt,-4pt);
  }%
}  

\tikzset{
myedge/.style={
  decoration={
   markings,
   mark=at position 0.5 with \node {\usebox\mybox};
  },
  postaction=decorate
  }
}
\begin{document}

\begin{figure}[h]
\centering
\scalebox{0.8}
{%
\begin{forest}
[$\nabla$
    [$\triangle$,edge={myedge}
        [$\nabla$
            [5]
            [1,edge={myedge}]
            [4]
        ]
        [$\nabla$,edge={myedge}
            [2]
            [7]
            [9]
        ]
        [$\nabla$
            [3]
            [5,edge={myedge}]
            [7]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [10]
            [2,edge={myedge}]
            [5]
        ]
        [$\nabla$
            [5]
            [6]
            [4,edge={myedge}]
        ]
        [$\nabla$
            [8]
            [9]
            [2,edge={myedge}]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [3]
            [7]
            [2,edge={myedge}]
        ]
        [$\nabla$,edge={myedge}
            [7]
            [6]
            [5]
        ]
        [$\nabla$,edge={myedge}
            [9]
            [8]
            [9]
        ]
    ]
]
\end{forest}
}
\caption{Minimax tree}
\end{figure}

\end{document}

enter image description here

  • I am up for learning new things but again this approach requires a lot of manual effort if you want to have correctly rotated cut-off branches markers if I am not mistaken... isn't there a package or functionality that provides this? Thanks for the tips @Gonzalo if you have any more shoot ;) – jtimz May 2 '14 at 2:55
  • @jtimz No manual work required at all. Please see my updated answer. – Gonzalo Medina May 2 '14 at 3:29
0

Forgive me if I've mistaken your intent, but is this the sort of thing you seek? If so, I just used a \stackinset. The syntax is

\stackinset{H-anchor:l,c,r}{H-offset}{V-anchor:t,c,b}{V-offset}{inset}{base image}

The insets may be nested, as I've shown here. This is a method of last resort, because the labels are placed (after the fact) on the tree by specifying physical lengths on the base image, rather than using logical indicators within the scope of the tree coding.

\documentclass[10pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{subfig}
\usepackage[latin1]{inputenc}                           % Input encoding
\usepackage{amsmath}                                    % Math
\usepackage{empheq}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{synttree}
\usepackage{stackengine}
\def\bigX{\sffamily\bfseries\Huge\textcolor{red}{$\times$}}
\begin{document}

\begin{figure}[h]
\centering
\stackinset{c}{-1.8cm}{c}{0.8cm}{\bigX}{%
\stackinset{c}{-0.5cm}{c}{}{\bigX}{%
\scalebox{0.8}
{
\branchheight{0.4in}
\childsidesep{1em}
\childattachsep{0.1in}
\synttree
[$\nabla$
    [$\triangle$
        [$\nabla$
            [5]
            [1]
            [4]
        ]
        [$\nabla$
            [2]
            [7]
            [9]
        ]
        [$\nabla$
            [3]
            [5]
            [7]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [10]
            [2]
            [1]
        ]
        [$\nabla$
            [5]
            [1]
            [4]
        ]
        [$\nabla$
            [8]
            [9]
            [2]
        ]
    ]
    [$\triangle$
        [$\nabla$
            [3]
            [1]
            [2]
        ]
        [$\nabla$
            [7]
            [6]
            [5]
        ]
        [$\nabla$
            [9]
            [8]
            [9]
        ]
    ]
]
}}}
\caption{Minimax tree}
\end{figure}
\end{document}

enter image description here

  • Yes @Steven, that exactly it, but how will I be able to space it nicely each time (for any branch that might get this treatment?) – jtimz May 1 '14 at 19:23
  • @jtimz This solution is purely manual, outside of the scope of the syntree package. As such, it is a method of last resort. – Steven B. Segletes May 1 '14 at 22:13

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.