2
$\begingroup$

If I create a legend panel with a label which includes the new line escape character "\n", e.g.

leg = SwatchLegend[{Red, Green, Blue}, 
{"red", "green", 
   "long\nverbose\ncolour"}, 
  LegendFunction -> (Framed[#, FrameStyle -> Thick] &),
  LegendMargins -> 5]

enter image description here

All of the text is aligned to the left, however, when The object is included in another graphic using Epilog->Inset[..]The alignment of the label containing "\n" is now raggedly centred.

tri = Graphics[{Thick, 
    Line[{{0, 0}, {100, 0}, {0.5*100, (Sqrt[3]/2)*100}, {0, 0}}]}];

Show[tri, Epilog -> Inset[leg, Scaled[{0.84, 0.74}]]]


Plot[2 Sin[x] - x, {x, 0, 6 Pi}, Frame -> True, 
 Epilog -> Inset[leg, Scaled[{0.8, 0.74}]]]

enter image description here

I've tried using Alignment->Left to no avail. While the SwatchLegend contains graphic elements it is not a Graphics object. Clearly something changes when it is placed with Inset.

Any suggestions on why this is happening? Is there a better way to convert it to a graphic before embedding it in Epilog?

$\endgroup$
2
$\begingroup$

Adding the option Alignment -> Left to Inset fixes the issue:

Row[{Show[tri, Epilog ->
   Inset[leg, Scaled[{0.84, 0.74}], Alignment -> Left], ImageSize -> 400],
  Plot[2 Sin[x] - x, {x, 0, 6 Pi}, Frame -> True, 
   Epilog -> Inset[leg, Scaled[{0.8, 0.74}], Alignment -> Left],  ImageSize -> 400]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.