MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: format mixed integers & floats with text styling (see )

  • To: mathgroup at
  • Subject: [mg82258] Re: format mixed integers & floats with text styling (see )
  • From: Helen Read <hpr at>
  • Date: Tue, 16 Oct 2007 03:32:18 -0400 (EDT)
  • References: <fesqmo$pdc$> <> <feuth9$6q$>
  • Reply-to: HPR <read at>

Murray Eisenberg wrote:
> Jean-Marc Gulliet wrote:
>>Murray Eisenberg wrote:
>>>Two years ago in  I posed this problem of formatting a table column 
>>>having a mixture of integers and approximate numbers in such a way 
>>>that the decimal point on the floats would be vertically aligned with 
>>>the implied decimal on the integers.
>>>For example, here's the data for the table:
>>>    statNames = {"N", "Max", "Min", "Mean", "", "Median"};
>>>    statNumbers = {40, 103, 2, 56.8, 22.5, 59};
>>>Now I need to complicate the problem by putting everything in a 
>>>non-default font, by using, e.g.,
>>> fmtTxt[txt_]:=Style[txt, FontFamily -> "Arial",FontSize->12]
>>You cannot use any font *and* keep the table aligned. To do so, you must 
>>use monospace fonts such as Courier or LucidaConsole (~~ Monaco on Mac). 
>>(Arial has glyphs of variable sizes.) 
> That's what I was afraid of, especially since the monospacing of 
> LucidaConsole is ugly (to my eyes).

This is all quite easy with Grid, which will take Alignment->"." (align 
to the decimal point) as an option. It seems to work with any font you 
may desire.

Murray told me via e-mail that he also wanted TableHeadings, with a 
horizontal line in between the headings and the table, the way TableForm 
outputs it. This is easy too -- just join an extra row with your 
headings, and use Dividers to get the horizontal line after the first row.

Grid[Join[{{"Statistic", "Value"}},
Transpose[{statNames, statNumbers}]],
Alignment -> {{Left, "."}, None},
ItemStyle -> {FontFamily -> "Arial", FontSize -> 12},
Dividers -> {None, {False, True}}]

You might also like a vertical line between the two columns, which you 
can do by setting Dividers like this.

Dividers -> {{False, True}, {False, True}}

Or, in place of Dividers, use Frame->All

I have gone over to Grid completely, and don't ever use TableForm any 
more. I can't see anything that TableForm can do that Grid cannot, and 
Grid will do a lot that TableForm won't. In fact, I'm not sure why WRI 
kept TableForm in 6.0. About the only thing Grid seems to lack is an 
option for RowLabels and ColumnLabels (which I would like), but you can 
always get around that by joining an extra row or column with your headings.

Helen Read
University of Vermont

  • Prev by Date: Re: Hiding Input Cells
  • Next by Date: Re: Re: Help with DateListPlot
  • Previous by thread: Re: format mixed integers & floats with text styling (see )
  • Next by thread: Re: format mixed integers & floats with text styling (see )