# How to add text next to nodes and prune (cut) parts of a tree?

I am having problems with how to align text next to nodes and also how to prune a tree. So far I have the following code and please ignore mistakes, I am not familiar with TikZ or LaTeX.

\usepackage{tikz} % Flow chart
\usetikzlibrary{shapes,arrows,positioning,calc,chains}
\usepackage{float, subcaption}

\begin{document}
\tikzstyle{test} = [rectangle, fill=white!20,
text width=0.1em, rounded corners, minimum height=8em]

\tikzset{
treenode/.style = {align=center, inner sep=0pt, text centered,
font=\sffamily},
arn_n/.style = {treenode, circle, black, font=\sffamily, draw=black,
fill=white, text width=1.5em},% arbre rouge noir, noeud noir
arn_r/.style = {treenode, circle, black, draw=black,
text width=1.5em},% arbre rouge noir, noeud rouge
arn_x/.style = {treenode, rectangle, draw=black,
minimum width=0.5em, minimum height=0.5em}% arbre rouge noir, nil
}

\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.26\textwidth}
\centering
\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 3cm/#1,
level distance = 1.5cm},baseline=(current bounding box.center)]

\node [arn_n] {33}
child{ node [arn_r] {15}
}
child{ node [arn_r] {47}
}
;
\end{tikzpicture}
\caption{}
\end{subfigure}%
\begin{subfigure}[b]{0.20\textwidth}
\centering
\begin{tikzpicture}
% Place nodes
\node [test] (empty) { } ;
\node [right of=empty, node distance=2cm] (empty1) {}  ;
% Draw edges
\path [line] (empty) -- (empty1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.26\textwidth}

\centering\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 3cm/#1,
level distance = 1.5cm}, baseline=(current bounding box.center)]
\node [arn_n] {33}
child{ node [arn_r] {15}
}
child{ node [arn_r] {47}
}
;
\end{tikzpicture}
\caption{}
\end{subfigure}
\caption{Pruned by infeasibility} \label{fig:3}
\end{figure}


This gives me the following:

Now I would like to end up with something like this:

I would like to add text next to the nodes so that I can state the upper and lower bound. I would also like to cut/prune parts of the tree.

I hope someone can help.

Best Regards

• This is how I would like to prune the three: emotion.inrialpes.fr/people/synnaeve/phdthesis/images/tikz3.png either with 2 line cuts or 1 line cuts – Husky653 Mar 6 '17 at 23:58
• Welcome to TeX.SE! Do you like that some make code (almost from scratch) for image on the link or only draw break in one branch? – Zarko Mar 7 '17 at 0:49
• Welcome! Don't make people follow links to wherever. Please upload pictures inline. Please post code we can compile in the form of a complete example. I tried to add your pictures, but the site doesn't like the format. – cfr Mar 7 '17 at 1:05
• Note to self: never, ever try to follow one of these links again. It took forever to do nothing except freezing my browser and then showed me a blank space. Tiny the pics maybe, but whatever the site does to my laptop is certainly not! – cfr Mar 7 '17 at 1:13

As starting point:

\documentclass{article}
\usepackage{tikz} % Flow chart
\usetikzlibrary{arrows, calc, positioning}
\usepackage{float, subcaption}

\begin{document}
\begin{figure}[ht]
\tikzset{
every label/.append style = {label distance=1pt, inner sep=1pt, align=left},
base/.style = {draw,
inner sep=1pt, minimum size=5mm, font=\sffamily},
arn_c/.style = {base, circle, fill=#1},% arbre rouge noir, noeud noir
arn_c/.default = white,
arn_r/.style = {base, rectangle, draw, fill=#1},% arbre rouge noir, nil
arn_r/.default = white,
}
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}[->,>=stealth',
level/.style={sibling distance = 22mm,
level distance = 1.5cm},
]
\node (a) [arn_c,label={right:$\alpha=3$}] {33}
child{ node (b) [arn_c] {15}}
child{ node (c) [arn_c] {47}}
;
\path   (a) -- node [sloped,label={[font=\footnotesize]60:$\beta$ cut}] {$\|$} (c);
\end{tikzpicture}
\caption{}
\begin{tikzpicture}[baseline=-17mm]
\draw  (0,0) -- (2,0);
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}[->,>=stealth',
level/.style={sibling distance = 22mm,
level distance = 1.5cm},
]
\node [arn_c,label={[blue]left:$\alpha=3$}] {33}
child{ node [arn_c] {15}}
child{ node [arn_c] {47}}
;
\end{tikzpicture}
\caption{}
\end{subfigure}
\caption{Pruned by infeasibility}
\label{fig:3}
\end{figure}
\end{document}


If you like to draw tree showed in image on given link, just add more children with desired node styles, and for text beside them use labels as is done in above MWE for root node.

Edit: for multi line labels you need add align=... to the definition of label style. For example, if the most of label are on the right side of nodes with font size \tiny, than

every label/.append style = {label distance=1pt, inner sep=1pt,


and for exceptions change this settings locally. For example

\path   (a) -- node [sloped,label={[font=\small]60:$\beta$ cut}] {$\|$} (c);


Both examples are now considered in MWE and present in image of trees.

• Thank you very much! I am now having issues with the label. I would like to have a label with line breaks such that I for example could have one line with number Y and second line with number X. I have tried to do the following modification of your code: \node [arn_c,label={[black]right: \tiny{27}\\ \tiny{13}}] {S} but it gives me the error saying "somethings wrong, perhaps an missing \item" and I also tried \node [arn_c,label={[black]right: \tiny{27}\newline \tiny{13}}] {S} but neither worked. Do you have any suggestions on what I could do? – Husky653 Mar 7 '17 at 13:51
• @Husky653, this wasn't clear from question :-(. you need add option align=... to your labels. if all are for example aligned on the same way, you can adopt presetting accordingly. See edit of my answer. – Zarko Mar 7 '17 at 13:53
• Thank you very much! And apologies for not being clear in my question. I used the following which also worked for me: \node [arn_c,label={[black]right: \shortstack{ \tiny{27} \\ \tiny{13}}}] which I got from the website: gnuplotting.org/line-breaks-in-labels – Husky653 Mar 7 '17 at 14:13
• If you are happy with your solution, than use it. However, ti has some drawbacks: line spacing in labels is still for \normalsize font, not for \tiny. Also the black color is default, so if you persist with your solution, try \node [arn_c,label={[font=\tiny]right: \shortstack{ 27\\ 13}}] {S} (not tested). – Zarko Mar 7 '17 at 14:18
• Thank you for your help! I will do that instead! Have a great day :) – Husky653 Mar 7 '17 at 14:22