Another possibility which may even give you help for the next time is, to look how Mathematica represents the two-colored Text you want. So go into a notebook and format the text as you like it with the font-menu. For instance
Now, while still being in this cell you press Ctrl+Shift+E
and you get (I commented the unimportant stuff out):
(*Cell[BoxData[*)
RowBox[{
StyleBox["subject",
FontVariations->{"Underline"->True},
FontColor->GrayLevel[0]],
StyleBox[":",
FontVariations->{"Underline"->True},
FontColor->GrayLevel[0]],
StyleBox["AK6",
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 1]]}] (*],
"Input",
CellChangeTimes->{{3.5377269466224403`*^9, 3.537726946623592*^9}}] *)
These are some of the low-level boxes used by Mathematica to set any expression you use in the front-end. The good thing is, you can use this directly in your code if you wrap this with DisplayForm
aboveBox[info_, colors_] :=
Graphics[{colors, EdgeForm[Thick], Rectangle[{0, 0}, {26, 3}], Text[
DisplayForm@
RowBox[{StyleBox["subject",
FontVariations -> {"Underline" -> True},
FontColor -> GrayLevel[0]],
StyleBox[":", FontVariations -> {"Underline" -> True},
FontColor -> GrayLevel[0]],
StyleBox[info, FontWeight -> "Bold",
FontColor -> RGBColor[1, 0, 1]]}]
, {26, 3}/2]}, ImageSize -> 300]
aboveBox["DrX", LightBlue]
Btw: Don't forget Inset
which can be used for this purpose too. Since Inset
can handle general objects you want to place inside a graphics, it seems it is more general and may become handy sometime.
Row[{Style["subject ",Black,10],Style["AK6",Pink,18]}]
$\endgroup$