Borrowing triangularArrayLayout from here, I have:
triangularArrayLayout[triArray_List, opts___] :=
Module[{n = Length[triArray]},
Graphics[MapIndexed[
Text[Style[#1,
Large], {Sqrt[3] (n - 1 + #2.{-1, 2}), 3 (n - First[#2] + 1)}/
2] &, triArray, {2}], opts]]
n = 6;
s = 500;
coeffs = triangularArrayLayout[Table[Row[{"C(", i, ",", j, ")"}], {i, 0, n}, {j, 0, i}],
ImageSize -> s];
tri = triangularArrayLayout[Table[Binomial[i, j], {i, 0, n}, {j, 0, i}],
ImageSize -> s];
layers = {Overlay[{coeffs, Show[tri, TextStyle -> GrayLevel[.8]]}, Alignment -> Top],
Overlay[{tri, Show[coeffs, TextStyle -> GrayLevel[.8]]}, Alignment -> Top]};
Manipulate[layers[[u]], {{u, 1, " "}, {1 -> "binomial coefficients",
2 -> "Pascal's triangle"}}, ControlType -> RadioButtonBar]
but the vertical alignment is off:

This is the main issue, but I am also curious how to:
- typeset the $C(n,r)$ as
TraditionalForm(with the varying $n$ and $r$ values throughout) - typeset the $C(n,r)$ as $_{n}C_{r}$ (also with the varying $n$ and $r$ values).
Answer
- Using the same option
ImagePadding->kin bothcoeffandtrifixes the vertical alignment problem. Cis a protected symbol (it is used for representing constants generated in symbolic computations.) Instead you can use\[ScriptCapitalC]:
Then
TraditionalForm[\[ScriptCapitalC][n,r]]
gives

and
TraditionalForm[\[ScriptCapitalC][9,3]]
gives

- For typsetting
C(n,r)as $_{n}C_{r}$
you can use
nCr /: MakeBoxes[nCr[n_, r_], StandardForm] :=
RowBox[{SubscriptBox["\[InvisiblePrefixScriptBase]", MakeBoxes[n, StandardForm]],
SubscriptBox["C", MakeBoxes[r, StandardForm]]}]
With
nCr[3, 2]
you get

and
TraditionalForm[nCr[3, 2]]
gives

Comments
Post a Comment