2
votes

I'm trying to get a nice legend for several of my plots, however, I can't get the text alignment of the Legend to change and it's doing all sorts of weird things.

The first thing is that the text alignment seems to be set to center when I want it to be aligned to the right, which you can see if you copy and pasty the following code:

Needs["PlotLegends`"]

ShowLegend[
 Plot[x, {x, 0, 10000}, 
  ImageSize -> {700, 
    Automatic}], {{{Style["\[FilledCircle]", 12, Red], 
    "3He exp 4 'sigma D 3He' 'stripping'"}, {Style["\[EmptySquare]", 
     12, Red], 
    "3He 'sigma 3He' 'breakup'"}, {Graphics@{Blue, Dashed, 
      Line[{{0, 0}, {2, 0}}]}, 
    "3He 'pickup' 'stripping'"}, {Graphics@{Blue, Dotted, 
      Line[{{0, 0}, {2, 0}}]}, 
    "3He 'breakup'"}, {Graphics@{Blue, Line[{{0, 0}, {2, 0}}]}, 
    "3He Total"}}, LegendPosition -> {0.0, 0.2}, 
  LegendSize -> {0.7, 0.3}, LegendShadow -> False, 
  LegendBorder -> None,
  LegendTextOffset -> {-0.2, 0}}]

(Note that the Plot of x is only a dummy plot here, the position of the legend is optimized to my actual plots)

The second problem I have is with a vertical alignment of a legend text. If I run this code:

ShowLegend[
 Plot[x, {x, 0, 10000}, 
  ImageSize -> {700, 
    Automatic}], {{{Style["\[FilledCircle]", 12, Red], 
    "3H exp"}, {Graphics@{Blue, Line[{{0, 0}, {2, 0}}]}, 
    "3H theory"}}, LegendPosition -> {-0.8, 0.3}, 
  LegendSize -> {0.4, 0.3}, LegendShadow -> False, 
  LegendBorder -> None, LegendTextOffset -> {-3.0, 0}}]

the first text description "3H exp" is all sorts of messed up. Not only is it horizontally way before the "3H theory" text, it's vertical alignment doesn't even line up with the red circle!

How can I fix these things?

1

1 Answers

0
votes

Your first problem can be solved by using LegendTextSpace instead of LegendTextOffset, e.g.

Needs["PlotLegends`"]; 
ShowLegend[Plot[x, {x, 0, 10000}, ImageSize -> {700, Automatic}], {{
   {Style["\[FilledCircle]", 12, Red], "3He exp 4 'sigma D 3He' 'stripping'"},
   {Style["\[EmptySquare]", 12, Red], "3He 'sigma 3He' 'breakup'"},
   {Graphics@{Blue, Dashed, Line[{{0, 0}, {2, 0}}]}, "3He 'pickup' 'stripping'"},
   {Graphics@{Blue, Dotted, Line[{{0, 0}, {2, 0}}]}, "3He 'breakup'"},
   {Graphics@{Blue, Line[{{0, 0}, {2, 0}}]}, "3He Total"}},
  LegendPosition -> {0.0, 0.2},
  LegendSize -> {0.7, 0.3},
  LegendShadow -> False,
  LegendBorder -> None,
  LegendTextSpace -> 6}]

For the next problem, this misalignment seems to be unavoidable, as you can see if you set LegendSize -> {0.7, 1.3} in the above code. As a work-around - keeping the legend spacing you desire - you could try the following:-

ShowLegend[Plot[x, {x, 0, 10000}, ImageSize -> {700, Automatic}], {{
   {Style["\[FilledCircle]", 12, Red], "3H exp"},
   {Style["\[FilledCircle]", 12, White], ""},
   {Graphics@{Blue, Line[{{0, 0}, {2, 0}}]}, "3H theory"}},
  LegendPosition -> {-0.8, 0.3},
  LegendSize -> {0.6, 0.15},
  LegendShadow -> False,
  LegendBorder -> None,
  LegendTextSpace -> 8}]