# Pascal's triangle in LaTeX, with pointing arrows [duplicate]

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

-

## marked as duplicate by Alan Munn, Marco Daniel, diabonas, Joseph Wright♦Oct 25 '11 at 16:23

If you make the triangle in TikZ, then you can use TikZ syntax to make the arrows. For the basic triangle, take a look at tex.stackexchange.com/q/17522/86 – Loop Space Oct 25 '11 at 12:47

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

\documentclass{article}
\usepackage{tikz}
\def\mkPascal#1{
\begin{tikzpicture}
\def\dx{20pt}
\def\dy{30pt}
\newcounter{i}
\stepcounter{i}
\node (\arabic{i}) at (0,0) {1};
\foreach [count=\i] \x in {2,...,#1}{
\pgfmathsetmacro{\lox}{\x-1}%
\pgfmathsetmacro{\loxt}{\x-3}%
\foreach [count=\j] \xx in {-\lox,-\loxt,...,\lox}{
\pgfmathsetmacro{\jj}{\j-1}%
\stepcounter{i}
\pgfmathsetmacro{\lbl}{\lox!/(\jj!*(\lox-\jj)!)}
\node  (\arabic{i}) at (\xx*\dx, -\lox*\dy) {\pgfmathint{\lbl}\pgfmathresult};
}
}
\newcounter{z}
\newcounter{xn}
\newcounter{xnn}
\pgfmathsetmacro{\maxx}{#1 - 1}
\foreach \x in {1,...,\maxx}{
\foreach \xx in {1,...,\x}{
\stepcounter{z}
\setcounter{xn}{\arabic{z}}
\setcounter{xnn}{\arabic{xn}}
\stepcounter{xnn}
\draw [->] (\arabic{z}) -- (\arabic{xn});
\draw [->] (\arabic{z}) -- (\arabic{xnn});
}
}
\end{tikzpicture}
}
\begin{document}
\mkPascal{8}
\end{document}


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:

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.

-

As @Andrew says, the best method would be to use tikz. A crude alternative is to put the arrows and numbers in alternating rows in a tabular environment.

\documentclass{article}
\begin{document}
\newcommand{\ap}{\ensuremath{\swarrow\,\searrow}}
\setlength{\tabcolsep}{0pt}
\begin{tabular}{ccccccccc}
&     &     &      & 1   &      &      &     & \\
&     &     &      & \ap &      &      &     & \\
&     &     & 1    &     &  1   &      &     & \\
&     &     & \ap  &     &  \ap &      &     & \\
&     & 1   &      & 2   &      & 1    &     & \\
&     & \ap &      & \ap &      & \ap  &     & \\
& 1   &     & 3    &     &  3   &      & 1   & \\
&\ap  &     & \ap  &     &  \ap &      & \ap & \\
1 &     & 4   &      & 6   &      & 4    &     & 1
\end{tabular}
\end{document}

-