MathGroup Archive 2007

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

Search the Archive

Re: Re: format mixed integers & floats with text styling

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82321] Re: [mg82254] Re: format mixed integers & floats with text styling
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 17 Oct 2007 04:12:03 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <fesqmo$pdc$1@smc.vnet.net> <200710160730.DAA08942@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

I had forgotten about this method, since a different one worked that was 
suggested back when I was using Version 5.  Thanks for reminding me.

The Grid method suggested by Helen Read in [mg82258] does seem to give 
greater control over the formatting of the table.  Thus the Dividers 
option allows insertion of vertical or horizontal rules at will within 
the table, and these rules can be given color, thickness, and dashing 
attributes.  For example (not very attractive, but instructive):


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

Can this be done with TableForm?

Ray Koopman wrote:
> On Oct 14, 3:23 am, Murray Eisenberg <mur... at math.umass.edu> 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", "Std.dev.", "Median"};
>>     statNumbers = {40, 103, 2, 56.8, 22.5, 59};
>>
>> The object was to combine these into a properly formatted table starting
>> from:
>>
>>     (* original table *)
>>     TableForm[Transpose[{statNames,statNumbers}]]
>>
>> A good solution was proposed by Valeri Astanoff (sorry, I don't have the
>> message reference number):
>>
>>    pad[x_Integer]:=PaddedForm[x,3];
>>    pad[x_Real]:=PaddedForm[x,4];
>>
>>    (* aligned table *)
>>    TableForm[Transpose[{statNames, pad /@ statNumbers}]]
>>
>> 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]
>>
>> so that the TableForm expression is changed to:
>>
>>    (* formatted table *)
>>    TableForm[Transpose[{fmtTxt/@statNames, fmtTxt/@ pad /@ statNumbers}]]
>>
>> Unfortunately, this now breaks the nice vertical alignment.  How can the
>> alignment of "aligned table" be restored but still use such text formatting?
>>
>> --
>> Murray Eisenberg                     mur... at math.umass.edu
>> Mathematics & Statistics Dept.
>> Lederle Graduate Research Tower      phone 413 549-1020 (H)
>> University of Massachusetts                413 545-2859 (W)
>> 710 North Pleasant Street            fax   413 545-1801
>> Amherst, MA 01003-9305
> 
> The suggestion I made two years ago in
> 
> http://forums.wolfram.com/mathgroup/archive/2005/Oct/msg00548.html
> 
> seems to work just fine with Times changed to Arial:
> 
> myForm[x_Integer,{n_,f_}] := ToString@PaddedForm[x, n-f ];
> myForm[x_,       {n_,f_}] := ToString@PaddedForm[x,{n,f}];
> 
> StyleForm[TableForm[Transpose[{statNames, StringReplace[
>           myForm[#,{4,1}]," "->"  "]&/@statNumbers}]],
>           FontFamily->"Arial"]
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Compile forgets assigned values inside Do unless they are initialised
  • Next by Date: Re: Efficient creation of regression design matrix
  • Previous by thread: Re: format mixed integers & floats with text styling (see )
  • Next by thread: Recursion limit: a good idea to ignore?