1
$\begingroup$

In the following Table

TableForm[{{1, 0}, {0, 1}}, 
 TableHeadings -> {{"x<=0", "x>0"}, {"y<=0", "y>0"}}]

I want to use the empty space in the top left corner to add "TITLE" to explain what the values in the table denote. Is this possible?

$\endgroup$
1
$\begingroup$

you can post process the output of Tableform :

exp00 = TableForm[{{1 + 1, 0}, {0, 1}}, TableHeadings -> {{"x<=0", "x>0"}, {"y<=0", "y>0"}}]
exp01 = ToBoxes[exp00] /. (x : GridBox[___]) :>  MapAt["\"some text\"" &, x, {1, 1, 1}];
exp02 = RawBoxes[exp01]  

enter image description here
enter image description here

Sometimes the insertion point (here : {1,1,1}) is a little tricky to find because the target is embedded in some wrapper boxes (such as TagBox, InterpretationBox ...)

$\endgroup$
2
$\begingroup$
Grid[Prepend[Join[List /@ {"x<=0", "x>0"}, {{1, 0}, {0, 1}}, 2], 
  {"Title", "y<=0", "y>0"}], 
 Dividers -> {{False, 2 -> True}, {False, 2 -> True}}]

enter image description here

Update: A variation on andre2314's approach to post-process:

addTitle[t_] := RawBoxes@Replace[ToBoxes@#, "\[Null]" :> t /. Style -> StyleBox, All] &


addTitle[Style["Title", 24, Red, Bold]]@
 TableForm[{{1, 0}, {0, 1}}, TableHeadings -> {{"x<=0", "x>0"}, {"y<=0", "y>0"}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. Marked as answered. But there's no way to do this with a table, then? So I can't do it with evaluated values? $\endgroup$ – Richard Burke-Ward Apr 3 at 9:55
  • $\begingroup$ @RichardBurke-Ward, I don't know of any way to do it using TableForm. $\endgroup$ – kglr Apr 3 at 9:57
  • $\begingroup$ OK. Case closed. Appreciated @kglr $\endgroup$ – Richard Burke-Ward Apr 3 at 10:15
  • $\begingroup$ Many apologies @kglr, but I have to accept the answer below as more complete. I appreciate both of your inputs, of course. $\endgroup$ – Richard Burke-Ward Apr 3 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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