[Tex/LaTex] Pascal’s triangle in LaTeX, with pointing arrows


Possible Duplicate:
Pascal's triangle in tikz

I tried making this in a tabular, and it sort of worked. But I was not able to insert any arrows. Is there any simple way to make the image below in LaTeX?

I.e., to make a version of Pascal's triangle in LaTeX, with arrows showing how the next row is made

Example of Pascal's triangle, desired output

Best Answer

You can have Tikz determine the numbers and draw the pascal triangle (given a depth) as follows:

    \node (\arabic{i}) at (0,0) {1};
    \foreach [count=\i] \x in {2,...,#1}{
      \foreach [count=\j] \xx in {-\lox,-\loxt,...,\lox}{
        \node  (\arabic{i}) at (\xx*\dx, -\lox*\dy) {\pgfmathint{\lbl}\pgfmathresult};
    \pgfmathsetmacro{\maxx}{#1 - 1}
    \foreach \x in {1,...,\maxx}{
      \foreach \xx in {1,...,\x}{
          \draw [->] (\arabic{z}) -- (\arabic{xn});
          \draw [->] (\arabic{z}) -- (\arabic{xnn});

First the nodes are drawn in the triangle configuration and their labels are determined. Second, we loop over the nodes again to draw the arrows, one to each child. The final result is as follows:

Pascal Triangle of depth 8

Unforunately, due to the use of faculties to calculate the node labels, you can't draw Pascal triangles of more than 8 levels. This could probably be increased by using the recursive definition for n choose k instead of this one.

Related Question