Expecting that "\n" can be used to indicate a change in style is like expecting to win a lottery without buying a ticket. "\n" has no special meaning to Style
or Text
; it's just another character.
However, something that might work for you can be built by defining a couple of functions, one to style the text lines and the other to make them into an aligned block.
align[Right] = {1, 0};
align[Center] = {0, 0} ;(* default *)
align[Left] = {-1, 0};
textLine[text_String, opts : OptionsPattern[]] :=
Text[
Framed[
Style[text, FilterRules[{opts}, Options[Style]]],
Background -> White, FrameStyle -> None], Null, Null]
You can give textLine
any option that Style
will accept. That provides a lot of flexibility in the formatting of a line of text.
textBlock[
lines : {Text[__] ..},
vSpace_?NumericQ,
xy : {_?NumericQ, _?NumericQ} : {0, 0},
align : {_, _} : align[Center]] :=
Module[{dxy = {0, vSpace}},
MapThread[
ReplacePart[#1, {2 -> #2, 3 -> #3}] &,
{lines,
Table[xy + i dxy, {i, 0, Length[lines] - 1}],
ConstantArray[align, Length[lines]]}]]
Here is how these functions would be used to produce two lines of text, the first having bold text and second having italic text. Also, a different font is specified for each line.
opts1 =
{FontFamily -> "Bookman Old Style", FontWeight -> Bold, FontSize -> 20};
opts2 =
{FontFamily -> "New Century Schoolbook", FontSlant -> Italic, FontSize -> 20};
txt =
textBlock[
{textLine["The quick brown fox ...", opts1],
textLine["... jumped over the lazy dog", opts2]},
-.3, {0, 0}, align[Left]];
Graphics[txt]
