Table with headings across multiple rows/columns

Evaluating

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

gives me What I would like to have is something like It doesn't have to be exactly like this but I would like to make clear which variable, $x$ or $y$, changes along rows and which along columns. Is this possible in Mathematica?

Also, within each cell, I would like to indicate what the upper and what the lower element represents, i.e. $x+y$ or $x-y$. My first idea was to insert a second header column (perhaps using Prepend but that got quite clunky) as shown in the second picture, but if someone can think of a better way, I'm open for suggestions.

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}] 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 : 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] Edit

Or better , thanks to Alexey Popkov's comment :

ToString@Format[TableForm[
Table[{x+y,x-y},{x,5},{y,5}],
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}}] • You can convert TableForm into the formatted plain text form using ToString: ToString[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}],OutputForm]. – Alexey Popkov May 30 '17 at 8:14
• Alternative method: ToString@Format[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}],OutputForm]. – Alexey Popkov May 30 '17 at 8:16