Re: formatting table with integers and floats in a column

*To*: mathgroup at smc.vnet.net*Subject*: [mg61409] Re: formatting table with integers and floats in a column*From*: "Ray Koopman" <koopman at sfu.ca>*Date*: Tue, 18 Oct 2005 02:45:01 -0400 (EDT)*References*: <20051016121525.UUOK13165.eastrmmtao01.cox.net@[172.18.52.8]> <divhbs$g8t$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

I should have used PaddedForm instead of NumberForm. myForm[x_Integer,{n_,f_}] := ToString@PaddedForm[x, n-f ]; myForm[x_, {n_,f_}] := ToString@PaddedForm[x,{n,f}] StyleForm[TableForm[Transpose[{statNames, myForm[#,{4,1}]&/@statNumbers}]], FontFamily->"Courier"] StyleForm[TableForm[Transpose[{statNames, StringReplace[ myForm[#,{4,1}]," "->" "]&/@statNumbers}]], FontFamily->"Times"] Murray Eisenberg wrote: > Yes, terrific. Now, if I want the FontFamily to be "Times", there's > still trouble! > > Bob Hanlon wrote: > > This does it by brute force. > > > > statNames={"N","Max","Min","Mean","Std.dev.","Median"}; > > > > statNumbers={40,103,2,56.8,22.5,59}; > > > > StyleForm[ > > TableForm[ > > Transpose[{statNames, > > If[IntegerQ[#], > > StringReplace[ > > ToString[ > > NumberForm[#,{4,1}, > > NumberPadding->{" ","0"}]], > > ".0"->" "], > > NumberForm[#,{4,1}, > > NumberPadding->{" ","0"}]]&/@ > > statNumbers}]], > > FontFamily->"Courier"] > > > > > > Bob Hanlon > > > > > >>From: Murray Eisenberg <murray at math.umass.edu> To: mathgroup at smc.vnet.net > >>Date: 2005/10/16 Sun AM 12:18:11 EDT > >>Subject: [mg61409] formatting table with integers and floats in a column > >> > >>I have a 2-column table whose first column consists of strings -- > >> > >> statNames = {"N", "Max", "Min", "Mean", "Std.dev.", "Median"}; > >> > >>-- and a column of corresponding numbers: > >> > >> statNumbers = {40, 103, 2, 56.8, 22.5, 59}; > >> > >>If I use > >> > >> TableForm[Transpose[{statNames, statNumbers}]] > >> > >>then of course all the numbers will be left-aligned on their leftmost > >>digits. > >> > >>I want to format the numbers in the table so that they will appear as > >>follows: > >> > >>N 40 > >>Max 103 > >>Min 2 > >>Mean 56.8 > >>Std.dev. 22.5 > >>Median 59 > >> > >>Notice that I want the integers to appear as integers -- WITHOUT any > >>trailing decimal point; but the alignment is to be as if the numbers > >>were aligned on the decimal points including the implicit, but > >>unprinted, decimal points in the integers. > >> > >>How?? > >> > >>I've tried various things with mapping NumberForm onto the individual > >>numbers but cannot quite get the correct effect. > >> > >>-- > >>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 > >> > >> > > > > > > > > -- > 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