Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The following,

table = 
  TableForm[ConstantArray[0, {3, 3}], 
   TableAlignments -> Right, 
   TableHeadings -> {None, {"One", "Two", "Three"}}]

generates a table with headings:

enter image description here

I see that its FullForm is

TableForm[
  List[
    List[HoldForm[\[Placeholder]], HoldForm[\[Placeholder]], HoldForm[\[Placeholder]]],
    List[HoldForm[\[Placeholder]], HoldForm[\[Placeholder]], HoldForm[\[Placeholder]]],
    List[HoldForm[\[Placeholder]], HoldForm[\[Placeholder]], HoldForm[\[Placeholder]]]],
    Rule[TableAlignments, Right],
    Rule[TableHeadings, List[None, List["One", "Two", "Three"]]
  ]
]

and I could parse this to retrieve the value of TableHeadings.

But is there a more canonical approach?

I found that for plots, one can use Options[plot], but I couldn't find a counterpart for tables.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Options seems to work just fine:

Options[table, TableHeadings]

(* {TableHeadings -> {None, {"One", "Two", "Three"}}} *)

... slightly generalized:

getopt[obj_, opt_] := opt /. Options[obj, opt]

getopt[table, TableHeadings]

(* {None, {"One", "Two", "Three"}} *)

share|improve this answer
    
D'oh! I tried that but my test case was flawed—the options were stripped while copy-pasting a table in TableForm for use in InputForm. Thank you. –  Andrew Cheong Feb 27 at 10:06
    
Hehe - happy to help :D –  Yves Klett Feb 27 at 10:06
Cases[InputForm[yourTableFormRefHere], HoldPattern[TableHeadings -> a_] :> a, Infinity]

Should do the trick.

share|improve this answer
    
Works, thanks! I realized though that Options does work and I was simply misusing it. –  Andrew Cheong Feb 27 at 10:06
    
@acheong87 - lol, I assumed based on the quality of your questions that it didn't, so didn't bother to check. We both get 1 DOH! point... –  rasher Feb 27 at 10:25
    
IMO, a completely reasonable assumption given the context, haha. –  Andrew Cheong Feb 27 at 10:26

Your Answer

 
discard

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.