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.

I want a table with a single column of data, and with headings along both the rows and the column. One might expect it to work like this:

TableForm[{"one", "two", "three"}, 
 TableHeadings -> {{"$10MM", "$20MM", "$30MM"}, {"col"}}]

But this does not work; it displays the data and the row labels correctly, but it does not label the column. What am I missing?

share|improve this question
2  
Your data consists of a single row... try TableForm[List /@ {"one", "two", "three"}, TableHeadings -> {{"$10MM", "$20MM", "$30MM"}, {"col"}}]... –  Yves Klett May 30 at 20:26
1  
TableForm[List /@ {"one", "two", "three"}, TableHeadings -> {{"$10MM", "$20MM", "$30MM"}, {"col"}}] –  belisarius May 30 at 20:31
1  
or {{"one"},{"two"},{"three"}} .. –  george2079 May 30 at 20:36
1  
@belisarius and you even got the upvote earlier! Man, I really seem to be a people person :D –  Yves Klett May 30 at 20:39
1  
@YvesKlett Me too! –  belisarius May 30 at 20:46

3 Answers 3

up vote 3 down vote accepted

You present a single row vector to TableForm, which is rather hankering for a column vector (or matrix).

Instead of {"one", "two", "three"} you need {{"one"}, {"two"}, {"three"}}. There are many ways to achieve this, one of them List /@ {"one", "two", "three"}:

TableForm[List /@ {"one", "two", "three"}, 
 TableHeadings -> {{"$10MM", "$20MM", "$30MM"}, {"col"}}]

Mathematica graphics

share|improve this answer

I would prefer:

Grid[{{"", "col"}}~Join~
  Transpose[{{"$10M", "$20M", "$30M"}, {"one", "two", "three"}}], 
 Dividers -> All]

because of its clarity and all the additional Grid-options.

share|improve this answer

To be different, and to illustrate behavior of TableForm which I previously described here, which is that directions flip with every additional List level:

TableForm[
 {{{"one", "two", "three"}}}, 
 TableHeadings -> {{Column@{"$10MM", "$20MM", "$30MM"}}, {"col"}}
]

There may be a cleaner way to do the headings than using Column but I can't think of it at the moment.

share|improve this answer

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.