Reputation: 85
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!
Upvotes: 4
Views: 3318
Reputation: 24336
Although it is safer to do styling with Style
you can actually color the characters of the string directly using the Format menu or keyboard shortcuts, and Mathematica will preserve it in the dynamic control:
Upvotes: 3
Reputation: 13131
you mean like this?
Manipulate[
wAB,
{{wAB,1,Row[{Style["A", Red], Style["B", Blue]}]},0,1,Appearance->"Labeled"}
]
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"}
]
]
Upvotes: 6
Reputation: 2020
If vertical position is x, you must print one letter on x, then count width (w) and print next letter with another color on the new position x+=w.
Upvotes: 0