8

The picture I load is my target:

enter image description here

This is my code in mathematica

    StringTemplate["``Ratio is ``,``Ratio is ``,``Ratio is ``,"][
 Sequence @@ 
  Flatten@Transpose[{{Style["red", Red, Bold], 
      Style["green", Green, Bold], Style["blue", Blue, Bold]}, {0.1, 
      0.2, 0.3}}]]

But the result is

enter image description here

What's problem in my code?Can Anybody give some advice?

yode
  • 26,686
  • 4
  • 62
  • 167

3 Answers3

5
Row@MapThread[
  Row[{Style[#1, ToExpression@#1, Bold], " Ratio is ", #2, #3}] &,
  {{"Red", "Green", "Blue"}, {0.1, 0.2, 0.3}, {", ", ", ", ""}}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
3
TemplateApply[
 StringTemplate["`` Ratio is ``, `` Ratio is ``, `` Ratio is ``"], 
 Flatten[Transpose[{ToString[#, StandardForm] & /@ {Style["Red", Red, 
       Bold], Style["Green", Green, Bold], 
      Style["Blue", Blue, Bold]}, {0.1, 0.2, 0.3}}]]]

enter image description here

yode
  • 26,686
  • 4
  • 62
  • 167
2

As per How to join Styled strings

str = StringJoin[
  ToString[Style["red ", Red], StandardForm],
  "Ratio is 0.1, ",
  ToString[Style["green ", Green], StandardForm],
  "Ratio is 0.2, ",
  ToString[Style["blue ", Blue], StandardForm],
  "Ratio is 0.3"]

enter image description here

StringQ[str]

True

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108