Skip to main content

output formatting - Row and Column Headings for a Grid


It would be useful for me if I could write:


Grid[{{a, b}, {c, d}, {e, f}}, 
GridHeadings -> {{"r1", "r2", "r3"}, {"c1", "c2"}}]

just like



TableForm[{{a, b}, {c, d}, {e, f}}, 
TableHeadings -> {{"r1", "r2", "r3"}, {"c1", "c2"}}]

except that I don't want the two lines TableForm produces.


How could I add this additional option to Grid?



Answer



data = {{a, b}, {c, d}, {e, f}};
head = {{"r1", "r2", "r3"}, {"c1", "c2"}};



Join[Transpose[{Join[{""}, head[[1]]]}], Join[head[[{2}]], data], 2] // Grid


enter image description here



Comments