Discussion:
How to display calculated numbers at specified location in tikz
(too old to reply)
Dave94705
2016-02-23 05:31:54 UTC
Permalink
I wish to display Pascal's Triangle using tikz. While ultimately, I hope to pretty it up, for now I just want to have a lines showing connecting points with the appropriate numbers at each node. I use the tikz math library to calculate the numbers but I cannot figure out how to display them where I want (print command doesn't take specified position as far as I can see). I stole the idea for using a matrix \c from page 641 of the TikzAndPGF manual -- also tried it with the int \c; line commented out.

Below LaTeX code draws the connecting lines as expected, but displays the values of \y,\x rather than \c{\y,\x} as I wanted.

Any suggestions for how display \c{\y,\x} at desired location or other ideas to accomplish what I am (clearly?) trying to do would be appreciated. Thanks, ds

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}

\begin{document}
\tikzmath{
function binomCoef(\n,\i) {% don't use factorial ratios as individual factorials get too big too quickly
int \l,\m;
let \m = 1;
if \i == 0 then {return 1 \relax;};
if \i == \n then {return 1 \relax;};
for \l in {1,...,\i} then \m = (\m * \l)/(\i - \l);
return \m \relax;
};
int \c;
function fillBinomCoefs(\n){
int \i,\j;
for \i in {0,...,\n}
for \j in {0,...,\i}
\c{\i,\j} = binomCoef(\i,\j);
return 1;
};
}
%
\begin{tikzpicture}[scale=2, evaluate={int \n, \l; let \n = 2; let \l = fillBinomCoefs(\n);}]
\foreach \y in {0,...,\n}{
\foreach \x in {0,...,\y}{
\draw ({\y-2*\x},-\y) node {\Large \c{\y,\x}};
\draw ({\y-2*\x},-\y) -- +(-1,-1);
\draw ({\y-2*\x},-\y) -- +(+1,-1);
};
}
\end{tikzpicture}
\end{document}
Kevin Ryde
2016-02-25 07:08:27 UTC
Permalink
Post by Dave94705
I wish to display Pascal's Triangle using tikz.
There's a texample at (if I have the right one)

http://www.texample.net/tikz/examples/pascals-triangle-and-sierpinski-triangle/

doing some \pgfmath to eval numbers into macros.

(Personally I found the several \pgfmath ways to do things slightly hard
going and stopped at simple \pgfmathparse :-).
Dave94705
2016-02-25 19:13:52 UTC
Permalink
Post by Kevin Ryde
Post by Dave94705
I wish to display Pascal's Triangle using tikz.
There's a texample at (if I have the right one)
http://www.texample.net/tikz/examples/pascals-triangle-and-sierpinski-triangle/
doing some \pgfmath to eval numbers into macros.
(Personally I found the several \pgfmath ways to do things slightly hard
going and stopped at simple \pgfmathparse :-).
Thank you, I ended up using the bigintcalc package, but your suggestion is much more direct. ds
Loading...