Table with headings across multiple rows/columns

In case you are not aware, you can add a third level of headings :

TableForm[Table[
{x + y, x - y}, {x, 5}, {y, 5}],
 TableHeadings -> {Table[x, {x, 10}], Table[y, {y, 10}],{x+y,x-y}}]

Unfortunatly, the result is not satisfactory :

enter image description here

you may be interested by this trick :

fileName=CreateTemporary[];
st=OpenWrite[fileName,FormatType-> OutputForm];
Write[st,TableForm[
 Table[{x + y, x - y}, {x, 5}, {y, 5}],
 TableHeadings -> {Table[x, {x, 5}], Table[y, {y, 5}],{x+y,x-y}},
 TableAlignments-> {Right,Top,Right}],
 ];
Close[st];
Import[fileName]  

enter image description here

Edit

Or better , thanks to Alexey Popkov's comment :

ToString@Format[TableForm[
Table[{x+y,x-y},{x,5},{y,5}],
Table‌​Headings->{Table[x,{‌​x,5}],Table[y,{y,5}]‌​,{x+y,x-y}},
TableAli‌​gnments->{Right,Top,‌​Right}],OutputForm] 

Edit (19 August 2019)

I have put in this chatroom , at the very beginning, the code for a function flatTableForm[]that does what you need (among other things).

flatTableForm[Table[{x + y, x - y}, {x, 10}, {y, 10}], 
 TableHeadings -> {Table[x, {x, 10}], 
   Table[y, {y, 10}], {x + y, x - y}}]  

enter image description here


It is easy to add a horizontal row of headers. You can use Prepend to add vertical headers to the actual data, and then use Gridwith Dividers:

Grid[{
      {" ", "x y", Sequence @@ Table[x, {x, 10}]}, 
      Sequence @@ MapThread[Prepend /* Flatten, 
                 {
                  Table[Column[{x + y, x - y}], {x, 10}, {y, 10}], 
                  Table[{Column[{"x+y", "x-y"}], x}, {x, 10}]
                 }]
      }, 
    Dividers -> {{2 -> True, 3 -> True}, 2 -> True}]

Blockquote