8

I am trying to create a LCM tree diagram which looks something like this:

http://static.prometheanplanet.com/images/resources/resource-thumbnails/thumb-nprealg-04-01-0002-diagram-thumb-lg-png.png

Also what is the code to draw circles around numbers?

lockstep
  • 250,273

3 Answers3

12

With my tikz-based package forest, this can be achieved in a very concise way:

screenshot

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest} mark/.style={circle,draw=red}
  [8[2,mark][4[2,mark][2,mark]]]
\end{forest}
\end{document}
cmhughes
  • 100,947
  • 2
    +1 This forest package looks like serious business!... – Count Zero Jan 27 '13 at 21:06
  • @CountZero tnx! it did take a serious amount of time to write it ... :-) – Sašo Živanović Jan 27 '13 at 21:35
  • 1
    Congratulations and a big thank you for you contribution. Can you please add your details in here http://meta.tex.stackexchange.com/questions/1181/who-are-the-package-maintainers-here ? You can use the proper icon for the dev-page. – percusse Jan 27 '13 at 22:25
  • Thanks. Added --- great idea having such a page! I didn't use the icon since forest-styles is only a style repository. – Sašo Živanović Jan 28 '13 at 00:27
  • @SašoŽivanović forest is indeed a very nice package. I'm wondering why you decided not to use the qtree .label syntax for node labels. I've got lots of legacy trees, so that switching to forest would take some effort. Would it be possible to support both styles? – Alan Munn Jan 28 '13 at 00:41
  • It was a matter of personal taste, really... I simply prefered synttree's syntax to qtrees. Legacy trees ... "native" support will surely not be possible, because forest (like synttree) requires every node, including leaves, to be bracketed. It might be possible, however, to create a style which would use forest's dynamic tree mechanism to cover the rudimentary qtree syntax. I'll think about it... – Sašo Živanović Jan 28 '13 at 01:02
  • @AlanMunn I did it! I believe the issue might be of general interest, so I have posted a self-answered question: http://tex.stackexchange.com/questions/95790/is-it-possible-to-emulate-qtree-with-forest --- and anyway, one has to advertise his work, right ;-) – Sašo Živanović Jan 29 '13 at 00:53
5

Tikz can do nice trees:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{center}
  \begin{tikzpicture}[thick]
    \node {8} 
    child { node[circle,draw=red] {2} }
    child { node {4} 
      child { node[circle,draw=red] {2} }
      child { node[circle,draw=red] {2} }
    };
  \end{tikzpicture}
\end{center}

\end{document}
Alex
  • 5,362
2

Just to add the obligatory tikz-qtree solution:

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[Red/.style={circle,draw=red}]
\Tree [.8 [.\node[Red] (A){2}; ]
          [.4 
            [.\node [Red] (B) {2}; ]
            [.\node [Red] (C) {2};]]]
\end{tikzpicture}
\end{document}

output of code

Alan Munn
  • 218,180