6
$\begingroup$

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:

enter image description here

How can I put a plus sign in the upper left hand corner, making the first row of headings +, 0, 1, and 2.

$\endgroup$

1 Answer 1

7
$\begingroup$

I'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}}
]

Mathematica graphics


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]

5 mod

$\endgroup$
2
  • $\begingroup$ Really nice answer. I want to thank you for all the help you've given me over the years. $\endgroup$
    – David
    Apr 18, 2016 at 22:28
  • $\begingroup$ @David You are very welcome! I am glad I could help. $\endgroup$
    – MarcoB
    Apr 18, 2016 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.