21
$\begingroup$

I have a plot showing 8 curves, and I'm able to define a line legend styled in either a column or a row version. I have the following code:

PlotLegends -> Placed[LineLegend[{Style[Subsuperscript[P, "E", "*"], 
 FontSize -> 23], 
Style[Subsuperscript[P, "E", "*"], FontSize -> 23], 
Style[Subsuperscript[P, "E", "*"], FontSize -> 23], 
Style["\[Tau]", FontSize -> 23], 
Style[Subsuperscript[P, "E", "miss"], FontSize -> 23], 
Style[Subsuperscript[P, "E", "miss"], FontSize -> 23], 
Style[Subsuperscript[P, "E", "miss"], FontSize -> 23], 
Style[Subsuperscript[P, "E", "**"], FontSize -> 23]}, LegendFunction -> (Framed[#, RoundingRadius -> 2, 
   FrameStyle -> LightGray] &), BaseStyle -> 21], {0.1, Top}]

Neither the row nor the column version is useful to me, since it usually intersects the curves in the figure. How can I make the legend display with 4 rows and 2 columns?

Is there any easy way to arrange this in Mathematica, i.e. just to set the number of rows and columns and then type the legends and Mathematica plots it?

$\endgroup$

1 Answer 1

35
$\begingroup$

There is an undocumented form of LegendLayout that is useful here:

LegendLayout -> {"Column", noOfColumns}

similarly for "Row" and their reversed cousins. So, in your case I would use

LegendLayout -> {"Column", 2}

giving

enter image description here

Obviously, you do not have to include the color list when you pass it to PlotLegends.

$\endgroup$
4
  • 1
    $\begingroup$ thats cool. thank you very much. mathematica is sometimes troublesome for me. $\endgroup$ Commented Mar 12, 2015 at 21:03
  • $\begingroup$ just one question. Is there a way to align the lines of the first and second column? $\endgroup$ Commented Mar 12, 2015 at 21:13
  • 6
    $\begingroup$ @Seyhmus They should align if each legend label has the same height. You can use Pane to fix a height, e.g.: Pane[#, {Automatic, 40}] & /@ {Style[Subsuperscript[P, "E", "*"], FontSize -> 23], Style[Subsuperscript[P, "E", "*"], FontSize -> 23], . . .} $\endgroup$
    – Mr.Wizard
    Commented Mar 12, 2015 at 21:40
  • $\begingroup$ @Mr.Wizard cool! respect! $\endgroup$ Commented Mar 12, 2015 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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