MathGroup Archive 2004

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

Search the Archive

Re: table format question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51458] Re: [mg51433] table format question
  • From: Ben Kovitz <bkovitz at acm.org>
  • Date: Sun, 17 Oct 2004 21:49:50 -0400 (EDT)
  • References: <200410170705.DAA07117@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Oct 17, 2004, at 12:05 AM, Murray Eisenberg wrote:

> counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68};
> papers = Plus @@ counts;
> pcts = 100. counts/papers;
> grades = {"A ","A-","B+","B ","B-","C+","C ","C-","D+","D ","F "};
> TableForm[Transpose[
>       {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}],
>       TableHeadings -> {None, {"Grade", "Number", "Per Cent"}}]
>
> 1. How can I get a 0 to display after the decimal point in the last
> column's first and last rows?  (I tried to wrap the entire thing with 
> an
> obvious PaddedForm expression, but that had the unfortunate effect of
> giving me decimals in the 2nd column, which should be integers without
> any decimal point or trailing decimal places whatsoever.)
>
> 2. How can I get the numbers in columns 2 and three to be
> right-justified?  (I tried TableAlignments but that didn't seem to do 
> it.)

Does this work?

counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68};
papers = Plus @@ counts;
pcts = 100. counts/papers;
grades = {"A ", "A-", "B+", "B ", "B-", "C+", "C ", "C-", "D+", "D ", 
"F "};
TableForm[Transpose[
       {grades, NumberForm[#, 3, NumberPadding -> {" ", ""}] & /@ counts,
       NumberForm[#, {4, 1}, NumberPadding -> {" ", "0"}] & /@ pcts}],
       TableHeadings -> {None, {"Grade", "Number", "Per Cent"}}]

I think the non-obvious tricks are the space as the first argument to 
NumberPadding to produce right-alignment, and the "0" as the second 
argument to pad with zeros on the right.

--
Ben Kovitz
Humboldt State University


  • Prev by Date: RealValued functions and their derivatives
  • Next by Date: Re: table format question
  • Previous by thread: table format question
  • Next by thread: Re: table format question