I have:
modadd = Table[Mod[i + j, 3], {i, 0, 2}, {j, 0, 2}];
TableForm[modadd,
TableHeadings -> {{0, 1, 2}, {0, 1, 2}}]
Which produces:
How can I put a plus sign in the upper left hand corner, making the first row of headings +, 0, 1, and 2.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'm afraid that you are going to have to build your own Grid
for that. I don't think that the top left position is accessible through TableHeadings
:
Grid[
Insert[Transpose@Join[{Range[0, 2]}, modadd], Flatten[{"+", Range[0, 2]}], 1],
Dividers -> {{False, True, False}, {False, True, False}}
]
Here's a helper function to generate these grids automatically:
Clear[modaddition]
modaddition[modulo_Integer] :=
Grid[
SparseArray[{
{1, 1} -> "+",
{1, i_} -> i - 2,
{j_, 1} -> j - 2,
{i_, j_} /; i != 1 && j != 1 -> Mod[i + j - 4, modulo]
},
{modulo + 1, modulo + 1}
],
Dividers -> {{False, True}, {False, True}}
]
modaddition[5]