Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have

m = {{0, -1, -2, -3, -4}, {1, 0, -1, -2, -3}, {2, 1, 0, -1, -2}, {3, 
    2, 1, 0, -1}, {4, 3, 2, 1, 0}};

And a grid Grid[m,Frame->All]

I would like to label the grid such that every column has a number above it and every row has a number to its side. This is what I've currently managed to do.


How can I label the grid appropriately?

share|improve this question
I highly recomment this answer by Mike Honeychurch but if you do not need such interface take a look at Headings option for TableForm. You can allways add such heading as a new column and row, then you have to read adding columns/rows. – Kuba May 2 '14 at 8:32
up vote 7 down vote accepted

Perhaps what you want:

m = Array[Subtract, {5, 5}, 0];
r = Range @ 5;

 ArrayFlatten[{{"", {r}}, {{r}\[Transpose], m}}],
 Frame -> All

enter image description here

share|improve this answer
Exactly what I was looking for. +1 For simplicity. – pyler May 2 '14 at 10:19

You could use TableForm, e.g.

col = CharacterRange["A", "E"];
row = CharacterRange["a", "e"];
TableForm[m, TableHeadings -> {row, col}]

A way using Grid:

Grid[{PadLeft[col, 6, ""]}~Join~
  MapThread[PadLeft[#1, 6, #2] &, {m, row}], 
 Dividers -> {{False, True, {False}}, {False, True, {False}}}]

enter image description here

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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