Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mathematica: how to have text in multiple colors?

I'd like to have a manipulate control, something like {{wAB, 1, "AB"}, 0, 1, Appearance -> "Labeled"}, but would like the A and the B to be different colors, say, Red and Blue.
I can change the overall color with Style["AB",Red], but haven't been able to get the A and the B in different colors. Any help would be appreciated!

like image 893
pedro silva Avatar asked Oct 31 '25 16:10

pedro silva


1 Answers

you mean like this?

Manipulate[
 wAB,
 {{wAB,1,Row[{Style["A", Red], Style["B", Blue]}]},0,1,Appearance->"Labeled"}
 ]

enter image description here

and if you prefer to define the decoration part separately (which can be useful for larger and more complicated controls) and reference it in controls later on (like declaring a variable, sort of, but it is a macro actually) and reuse it for different controls, then you can use With, like this

Manipulate[wAB,

 Evaluate@With[

   {myStyle = Row[{Style["A", Red], Style["B", Blue]}]},

   {{wAB, 1, myStyle}, 0, 1, Appearance -> "Labeled"}

   ]
 ]
like image 199
Nasser Avatar answered Nov 03 '25 02:11

Nasser