Re: Displaying a table
- To: mathgroup at smc.vnet.net
- Subject: [mg110105] Re: Displaying a table
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Wed, 2 Jun 2010 02:04:26 -0400 (EDT)
First, I don't see what using subx has to do with this: You simply are forming a square table of a fixed sizelength, which in your case is 6 by 6. So just: circorr = Table[0, {6}, {6}]; circorr[[2, 5]] = 6; circorr[[3, 4]] = 8; Second, in the example shown, I don't see any decimals; none of the numbers shown are approximate. If you're getting numbers that ought to be integers but have a trailing decimal, you could use Rationalize on them. Third, here's a way to conditionally replace any entry that's positive with a bold-face styling; for emphasis, I've also changed the font size. Step 1. Define a (delayed) rule that replaces anything positive with the styled version of it: whenPositive = x_?Positive :> Style[x, 18, Bold] Step 2. Use that on the table, as is or inside TableForm: circorr /. whenPositive TableForm[circorr /. whenPositive] Or do the same thing with Grid, where you have probably finer control over spacing than you can do with Table (although where you'll need to explicitly adjoin any needed rows or columns for table headings): Grid[circorr /. whenPositive] On 6/1/2010 4:22 AM, S. B. Gray wrote: > I need to display the subx table as shown, with no decimal points or {} > and with some spaces between columns. Some entries will be nonzero and > it would be nice to show them in boldface. I tried Style with Positive > but didn't succeed. This method works but there must be a better way. > > > subx = {0, 0, 0, 0, 0, 0}; (* this is an example *) > lenx = Length[subx]; > circorr = Table[0, {lenx}, {lenx}]; > circorr[[2, 5]] = 6; > circorr[[3, 4]] = 8; (* Only examples. *) > ts1 = ToString[circorr]; > ts1 = StringReplace[ts1, ", " -> " "]; > ts1 = StringReplace[ts1, "{" -> ""]; > ts1 = StringReplace[ts1, "}" -> "\r"]; (* To print>0 in Bold? *) > Print[" ", TableForm[ts1]] (* which gives this: *) > > 0 0 0 0 0 0 > 0 0 0 0 6 0 > 0 0 0 8 0 0 > 0 0 0 0 0 0 > 0 0 0 0 0 0 > 0 0 0 0 0 0 > > Thanks to everyone for past and present help. > > Steve Gray > -- Murray Eisenberg murrayeisenberg at gmail.com 80 Fearing Street phone 413 549-1020 (H) Amherst, MA 01002-1912