1

I need to make a binary tree

How can I see such tree in my document? I've got margins

\usepackage{geometry} 
\geometry{top=25mm} 
\geometry{bottom=35mm} 
\geometry{left=35mm} 
\geometry{right=20mm}
  • Welcome to TeX.SX! You've already tagged this question with {tikz-pgf}. What specifically do you have problem with? What have your tried so far? In its current form this question seems like a duplicate of various tree questions on this ite, e.g. Unbalanced binary tree with forest. – siracusa Oct 10 '19 at 5:49
2

Welcome! With forest, which is based on TikZ, this is straightforward. You need to replace X,Y,Z by your numbers.

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={parent anchor=south}
 [{$(1,1,1)$}
  [{$(2,1,1)$}
   [{$(2,5,1)$}
    [{$(13,1,5)$}
     [{$(X,Y,Z)$}
      [{$(X,Y,Z)$}
      ]
      [{$(X,Y,Z)$}
      ]
     ]
     [{$(X,Y,Z)$}
      [{$(X,Y,Z)$}
      ]
      [{$(X,Y,Z)$}
      ]
     ]
    ]
    [{$(2,5,29)$}
     [{$(X,Y,Z)$}
      [{$(X,Y,Z)$}
      ]
      [{$(X,Y,Z)$}
      ]
     ]
     [{$(X,Y,Z)$}
      [{$(X,Y,Z)$}
      ]
      [{$(X,Y,Z)$}
      ]
     ]
    ]
   ]
  ]
 ]
\end{forest}
\end{document}

enter image description here

  • 2
    Since all the nodes are math, you might as well add math content as an option and ditch all the $. – Alan Munn Oct 10 '19 at 6:04
  • How I can change the size, cause I've such margins \usepackage{geometry} \geometry{top=25mm} \geometry{bottom=35mm} \geometry{left=35mm} \geometry{right=20mm} – Ruslan Nevretdinov Oct 10 '19 at 13:55
  • @RuslanNevretdinov The current tree fits in such a document, but it won't fir if one adds all the numbers you have. Then the options include making the font smaller, decreasing the distances between siblings or using something like adjustbox to make the tree fit. – Schrödinger's cat Oct 10 '19 at 14:30

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.