Re: Color coding a Table entry

• To: mathgroup at smc.vnet.net
• Subject: [mg92688] Re: Color coding a Table entry
• From: AES <siegman at stanford.edu>
• Date: Fri, 10 Oct 2008 04:36:50 -0400 (EDT)
• Organization: Stanford University
• References: <gckmm5\$naj\$1@smc.vnet.net>

```Original post:

> I'm Printing (to the screen) a Table like, let's say,
>
>    Table[{f1, f2, f3}, (x, xmin, xmax}]
>
> and anytime the value of f2 goes negative I want that value printed in
> Red.   What's a simple, compact way to code this?

Of the dozen or so replies, I'd say that

> Table[{f1, Style[f2, If[f2 < 0, Red, Black]], f3}, {x, -1, 5}]
>
>
> Bob Hanlon

is by far the best:  simple, clean, you can see what it does, no arcane
symbols, no cross effects on anything else outside that entry (and, the
solution I'd already come up with on my own).

If the conditional in the If[ ] statement got lengthy, to avoid
cluttering up the Table with it I might go to the alternative suggestion

>     redneg[expr_] := If[cond[expr], Style[expr, Red], expr, expr]
>
>     With[{xmin = 0, xmax = 10},
<      Table[{f1, redneg[f2], f3}, {x, xmin, xmax}]]
<
>  Regards, Jean-Marc

Or, just define the conditional separately, outside the Table,

cond[expr_] : = <<something>>

and use

Style[f2, If[fcond[f2], Red, Black]]

in the Table.

Would  Plot[redneg[f[x]], {x, xmin, xmax}]  make the plot turn black
below the x axis???   Have to try it and see . . .

```

• Prev by Date: Unevaluated subtleties
• Next by Date: Re: NumberSigns and Number Formatting
• Previous by thread: Re: Color coding a Table entry
• Next by thread: Re: Color coding a Table entry