Pascal's triangle fixed. Have to use Grid[ ].
- To: mathgroup at smc.vnet.net
- Subject: [mg121185] Pascal's triangle fixed. Have to use Grid[ ].
- From: "Christopher O. Young" <cy56 at comcast.net>
- Date: Sat, 3 Sep 2011 08:04:41 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
For some reason, Row[ ] doesn't have the ItemSize option, so I have to use
Grid[ ] in order to set all items to the same size in all the rows. This
gets the entries lined up right. The ItemSize, however, seems to be
magnified a lot from the "number of ems", which the documentation claims it
is supposed to take.
Chris Young
pascalTri6[n_] :=
Module[
{max, cellWd}, (* Maximum entry. Cell width. *)
max = Max[Table[Binomial[n, j], {j, 0, n}]];
cellWd = 0.25*IntegerLength[max] + 2;
Column[
Table[
Grid[
{Table[Binomial[i, j], {j, 0, i}]},
ItemSize -> {cellWd, 2},
Alignment -> Center
],
{i, 0, n}
],
Center
]
]
I'm trying to get the same spacing between the _center points_ of each of
the numbers in the Pascal triangle, so that each entry in a row is centered
properly underneath the corresponding two entries in the row above. Instead,
all the spacing options for Row[ ] seem to just apply to the spacings
between numbers.
It looks like I would have to calculate the length (i.e., number of digits)
of each entry as I go through the table. Is DigitCount the best function to
use here? I.e., won't slow things down too much? Or is there a faster way?
Thanks for any help.
Chris Young
cy56 at comcast.net
pascalTrngl2[n_] :=
Module[
{max, sp},
max = Max[Table[Binomial[n, j], {j, 0, n}]];
sp = Round[N[Log[10, max], 5]];
Column[
Table[
Row[
Table[Binomial[i, j], {j, 0, i}],
Invisible[sp]
],
{i, 0, n}
],
Center
]
]