2

I want to draw a picture like following:

enter image description here

\begin{tikzpicture} [ level 1/.style={sibling distance=30mm}, 
level 2/.style={sibling distance=15mm},
level 3/.style={sibling distance=7mm},
triangle/.style = {fill=blue!20, regular polygon, regular polygon sides=3},
node rotated/.style = {rotate=180},
border rotated/.style = {shape border rotate=180}]
\node[triangle] {1.5} 
    child {node[circle, draw, fill=blue!20] {1.5} 
        child {node[triangle, border rotated] {2} 
            child {node {2}}
            child {node {2}}}
        child {node[triangle, border rotated] {1}
            child {node {1}}
            child {node {2}}}}
    child {node[circle, draw, fill=blue!20] {-0.5}
        child {node[triangle, border rotated] {0}
            child {node {0}}
            child {node {2}}}
        child {node[triangle, border rotated] {-1}
            child {node {-1}}
            child {node {0}}}};
\end{tikzpicture}

This is my code. I've viewed this question TikZ: turning edges into arrows using "child" notation However when I add edge to parent, it will make whole tree's edge with arrow. I don't know how to make only one edge to red and arrow and don't change others. Thank you for your help.

  • You might make it yourself easier if you label your nodes, if you label them you can draw arrows between them. – Bart Sep 20 '19 at 7:53
3

You can always declare an edge from parent style on desired node and revert it in descendant branches

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture} [ level 1/.style={sibling distance=30mm}, 
level 2/.style={sibling distance=15mm},
level 3/.style={sibling distance=7mm},
triangle/.style = {fill=blue!20, regular polygon, regular polygon sides=3},
node rotated/.style = {rotate=180},
border rotated/.style = {shape border rotate=180}]
\node[triangle] {1.5} 
    child {node[circle, draw, fill=blue!20] {1.5} edge from parent[->, thick, draw=red]
        child {node[triangle, border rotated] {2} edge from parent[-, thin, draw=black] 
            child {node {2}}
            child {node {2}}}
        child {node[triangle, border rotated] {1} edge from parent[-, thin, draw=black]
            child {node {1}}
            child {node {2}}}}
    child {node[circle, draw, fill=blue!20] {-0.5}
        child {node[triangle, border rotated] {0}
            child {node {0}}
            child {node {2}}}
        child {node[triangle, border rotated] {-1}
            child {node {-1}}
            child {node {0}}}};
\end{tikzpicture}
\end{document}

enter image description here

3

An answer by using styles:

The output is like @Ignasi's answer output but I used styles and didn't made the arrow thick:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture} [ level 1/.style={sibling distance=30mm}, 
level 2/.style={sibling distance=15mm},
level 3/.style={sibling distance=7mm},
triangle/.style = {fill=blue!20, regular polygon, regular polygon sides=3},
node rotated/.style = {rotate=180},
border rotated/.style = {shape border rotate=180},
mystyle/.style={-latex,red},
mydefault/.style={-,black}
]
\node[triangle] {1.5} 
    child[mystyle]  { node[circle, fill=blue!20,draw=black,text=black]  {1.5}
        child[mydefault] {node[triangle, border rotated] {2} 
            child {node {2}}
            child {node {2}}}
        child[mydefault] {node[triangle, border rotated] {1}
            child {node {1}}
            child {node {2}}}}
    child {node[circle, draw, fill=blue!20] {-0.5}
        child {node[triangle, border rotated] {0}
            child {node {0}}
            child {node {2}}}
        child {node[triangle, border rotated] {-1}
            child {node {-1}}
            child {node {0}}}};
\end{tikzpicture}
\end{document}

PS: I wrote that answer many hours before (but then had some urgent chats about work) and just adding because it is ready.

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.