2
$\begingroup$

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.

$\endgroup$

2 Answers 2

4
$\begingroup$

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"}} *)

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Feb 27, 2014 at 10:06
  • $\begingroup$ Hehe - happy to help :D $\endgroup$
    – Yves Klett
    Feb 27, 2014 at 10:06
3
$\begingroup$
Cases[InputForm[yourTableFormRefHere], HoldPattern[TableHeadings -> a_] :> a, Infinity]

Should do the trick.

$\endgroup$
3
  • $\begingroup$ Works, thanks! I realized though that Options does work and I was simply misusing it. $\endgroup$ Feb 27, 2014 at 10:06
  • $\begingroup$ @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... $\endgroup$
    – ciao
    Feb 27, 2014 at 10:25
  • $\begingroup$ IMO, a completely reasonable assumption given the context, haha. $\endgroup$ Feb 27, 2014 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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