1

I dont know which packages should I use to make this code work, please, someone help me.

\begin{tikzpicture}[scale=1.5,font=\footnotesize]

\tikzset{

solid node/.style={circle,draw,inner sep=1.5,fill=black},

hollow node/.style={circle,draw,inner sep=1.5}

}

% Specify spacing for each level of the tree

\tikzstyle{level 1}=[level distance=10mm,sibling distance=37mm]

\tikzstyle{level 2}=[level distance=10mm,sibling distance=20mm]

\tikzstyle{level 3}=[level distance=15mm,sibling distance=10mm]

\tikzstyle arrowstyle=[scale=1]

\tikzstyle directed=[postaction={decorate,decoration={markings,

mark=at position .5 with {\arrow[arrowstyle]{stealth}}}}]



\node(0)[solid node,label=above:{$1$}]{}

child{node(1)[solid node, label=left:{$2$}]{}

child{node(3)[solid node]{}

child{node[hollow node,label=below:{$(6,3)$}]{}edge from parent node[left]{$G$} }

child{node[hollow node,label=below:{$(1,4)$}]{} edge from parent node[right]{$H$}}

edge from parent node[left]{$C$}}

child{node(4)[solid node]{}

child{node[hollow node,label=below:{$(1,2)$}]{}edge from parent node[left]{$G$} }

child{node[hollow node,label=below:{$(3,2)$}]{} edge from parent node[right]{$H$}}

edge from parent node[right]{$D$}

}

edge from parent node[left,xshift=-3]{$A$}

}

child{node(2)[solid node,label=right:{$2$}]{}

child{node(6)[solid node,label=right:{$1$}]{}

child{node[hollow node,label=below:{$(2,3)$}]{}edge from parent node[left]{$I$} }

child{node[hollow node,label=below:{$(1,4)$}]{} edge from parent node[right]{$J$}}

edge from parent node[left]{$E$}}

child{node(7)[solid node,label=right:{$1$}]{}

child{node[hollow node,label=below:{$(2,3)$}]{}edge from parent node[left]{$K$} }

child{node[hollow node,label=below:{$(3,2)$}]{} edge from parent node[right]{$L$}}

edge from parent node[right]{$F$}

}

edge from parent node[right,xshift=3]{$B$}

};



\draw[dashed,rounded corners=10]($(3) + (-.2,.25)$)rectangle($(4) +(.2,-.25)$);


\node at ($(3)!.5!(4)$) {$1$};

\end{tikzpicture}
siracusa
  • 13,411
  • 2
    Welcome! There are tons of errors, starting from the fact that some of your \tikzstyle commands, such as “\tikzstyle arrowstyle “, do not have the necessary braces. Note that \tikzstyle is deprecated anyway. –  Oct 04 '19 at 02:01
  • 2
    Two days of lost in the tikz wilderness now. Beginning to have had enough – Robin Jun 23 '21 at 10:16

2 Answers2

1

In your MWE are missed curly parenthesis and one child node. See @ Schrödinger's cat comment. Corrected and better formatted code is:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{fit}

\begin{document}
    \begin{tikzpicture}[scale=1.5,font=\footnotesize]
\tikzset{
 solid node/.style = {circle,draw,inner sep=1.5,fill=black},
hollow node/.style = {circle,draw,inner sep=1.5},
% Specify spacing for each level of the tree
    level 1/.style = {level distance=10mm,sibling distance=37mm},
    level 2/.style = {level distance=10mm,sibling distance=20mm},
    level 3/.style = {level distance=15mm,sibling distance=10mm},
   directed/.style = {postaction={decorate,decoration={markings,
                        mark=at position .5 with {\arrow{stealth}}}}
                     }% where you like to use this style?   
        }% end of tikzset
% tree
\node(0)[solid node,label=above:{$1$}]{}
% left branch
    child{node(1)[solid node, label=left:{$2$}]{}
        child{node(3)[solid node]{}
            child{node[hollow node,label=below:{$(6,3)$}]{} edge from parent node[left]{$G$} }
            child{node[hollow node,label=below:{$(1,4)$}]{} edge from parent node[right]{$H$}}
        edge from parent node[left]{$C$}
            }
        child{node(4)[solid node]{}
            child{node[hollow node,label=below:{$(1,2)$}]{} edge from parent node[left]{$G$} }
            child{node[hollow node,label=below:{$(3,2)$}]{} edge from parent node[right]{$H$}}
        edge from parent node[right]{$D$}
            }
    edge from parent node[left,xshift=-3]{$A$}
        }
% right branch
    child{node(2)[solid node,label=right:{$2$}]{}
        child{node(6)[solid node,label=right:{$1$}]{}
            child{node[hollow node,label=below:{$(2,3)$}]{} edge from parent node[left]{$I$} }
            child{node[hollow node,label=below:{$(1,4)$}]{} edge from parent node[right]{$J$}}
        edge from parent node[left]{$E$}}
        child{node(7)[solid node,label=right:{$1$}]{}
            child{node[hollow node,label=below:{$(2,3)$}]{}edge from parent node[left]{$K$} }
            child{node[hollow node,label=below:{$(3,2)$}]{} edge from parent node[right]{$L$}}
        edge from parent node[right]{$F$}
            }
    edge from parent node[right,xshift=3]{$B$}
        };
%
\node[draw,dashed,rounded corners=10,inner sep=8, 
      fit=(3) (4),
      label=center:$1$] {};
\end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517
0

The errors come from missing braces. However, I cannot refrain from suggesting an alternative: forest. Borrowing from this nice answer you can simplify the code to

\documentclass{article}
\usepackage[edges]{forest}
\forestset{declare toks={elo}{}} % https://tex.stackexchange.com/a/278184
\begin{document}
\begin{forest}
for tree={s sep+=2em,circle,draw,inner sep=1.5pt,
    where n children=0{fill=white}{fill=black},
    decision edge label/.style n args=3{
    edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$#3$}}
  },
  decision/.style={if n=1
    {decision edge label={left}{east}{#1}}
    {decision edge label={right}{west}{#1}}
  },
    }
 [,label=above:1
  [,label=left:2,decision=A
   [,decision=C
    [,label=below:{$(6,3)$},decision=H]
    [,label=below:{$(1,4)$},decision=I]
   ]
   [,decision=D
    [,label=below:{$(1,2)$},decision=J]
    [,label=below:{$(3,2)$},decision=K]
   ]
  ]
  [,label=right:2,decision=B
   [,decision=E
    [,label=below:{$(2,3)$},decision=L]
    [,label=below:{$(1,4)$},decision=M]
   ]
   [,decision=F
    [,label=below:{$(2,3)$},decision=N]
    [,label=below:{$(3,2)$},decision=O]
   ]
  ]
 ]
\end{forest}
\end{document}

enter image description here