I want to make something like this. Quadratic Sequence

I tried using tree diagrams and got this code,

% \usepackage{poker}
  style = enumerate ,
  counter-format = tsk),
  label-align = right,
  label-width = 2em,
  label-offset = .75em
  %label-format = \bfseries
\newcommand{\N}{\mathbb N}
\newcommand{\Q}{\mathbb Q}
\newcommand{\C}{\mathbb C}
\newcommand{\Z}{\mathbb Z}

% Set the overall layout of the tree
\tikzstyle{level 2}=[level distance=2cm, sibling distance=6cm]
\tikzstyle{level 3}=[level distance=2cm, sibling distance=3cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

\begin{tikzpicture}[grow=up, sloped]
\node {}
    child {
        node[bag] {$2a$}
        child {
            node[bag] {$5a+b$}
            child {
                node {$16a+4b+c$}
            child {
                node {$9a+3b+c$}
        child {
            node[bag] {$3a+b$}
            child {
                node {$4a+2b+c$}
            child {
                node {$a+b+c+d$}

which yields this result:my version

The problem with this is if I do another set that includes another 2a, those two 2a's will branch into one node. How should I change my code?

  • Welcome! Can you remove irrelevant stuff from your preamble? I'm not really sure what you mean by branching into one node. Generally, tree-drawing packages are designed for trees, which have a single root. It might be easier to use the matrix library.
    – cfr
    Sep 1, 2017 at 12:46
  • You can use a phantom root (and the standard trees doesn't care anyway), but the real problem is that tree nodes have at most one parent each and not, as in the case of biological organisms, two.
    – cfr
    Sep 1, 2017 at 12:50

1 Answer 1


Trees have a single root and every non-root node has one parent. Generally, packages designed to draw trees are specialised software for drawing trees in this sense and not, say, more generalised graphs. The TikZ library doesn't mind multiple roots, but it is still tricky to deal with multiple parents and so on.

I think it would be easier to think of the diagram as a matrix with some edges drawn between some of the nodes.

For example,

  \matrix (M) [matrix of math nodes]
    & n=1 && n=2 && n=3 && n=4\\
   T_n & a+b+c && 4a+2b+c && 9a+3b+c && 16a+4b+c\\
   \text{1\textsuperscript{st} difference} & & 3a+b && 5a+b && 7a+b & \\
   \text{2\textsuperscript{nd} difference} & & & 2a && 2a &&\\
  \draw (M-2-2) -- (M-3-3) -- (M-4-4) -- (M-3-5) edge (M-2-4) edge (M-2-6) -- (M-4-6) -- (M-3-7) edge (M-2-6) -- (M-2-8) ;



  • i would draw line as \draw (M-2-2) -- (M-3-3) -- (M-2-4) -- (Mm-3-5) -- (M-2-6) -- (M-3-7) -- (M-2-8) (M-3-3) -- (M-4-4) -- (M-3-5) -- (M-4-6) -- (M-3-7); ... you were faster than me for few minutes :(
    – Zarko
    Sep 1, 2017 at 13:45
  • @Zarko Too much typing :-).
    – cfr
    Sep 1, 2017 at 14:38

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.