12

I want to create a single column LineLegend with at least 12 different entries. Suppose that I define lists colors and names as follows:

colors = {Red, Magenta, Pink, Orange, Yellow, Green, Darker[Green], 
   Cyan, Blue, Purple, Black, Gray};
names = Table["Color " <> ToString[i], {i, 1, Length[colors]}];

If I use colors[[;; 10]] to show only the first 10 entries in LineLegend with LegendLayout -> "Column", I get a nice single column LineLegend:

LineLegend[colors[[;; 10]], names, LegendLayout -> "Column", 
 LabelStyle -> {20, FontFamily -> "Arial"}]

singleColumn

However, if I show 11 or more entries, the legends become double-columned:

LineLegend[colors[[;; 11]], names, LegendLayout -> "Column", 
 LabelStyle -> {20, FontFamily -> "Arial"}]

doubleColumn1

LineLegend[colors, names, LegendLayout -> "Column", 
 LabelStyle -> {20, FontFamily -> "Arial"}]

doubleColumn2

How can I force LineLegend to put the legend entries in a single column?

Andrew
  • 10,569
  • 5
  • 51
  • 104
  • 2
    f[pairs_] := Grid[pairs]; LineLegend[colors, names, LegendLayout -> f, LabelStyle -> {20, FontFamily -> "Arial"}] gives Mathematica graphics – Nasser Apr 12 '14 at 17:09

2 Answers2

24

There is an easier answer to this (esp. if you don't want to custom-specify colors), at least in version 10, found as the answer to this question:

LegendLayout -> {"Column", 1}]

All credit goes to MinHsuan Peng who answered that question, I just reposted here because I found this page first and thought other people searching for this would like to find this solution first too.

It's really disappointing (I wish I could say surprising) that this option isn't even listed in the "Possible settings for LegendLayout" in the details section of the Mathematica documentation.

Aaron Bramson
  • 937
  • 7
  • 17
7

You can define a layout function as shown in the documentation :-

colors = {Red, Magenta, Pink, Orange, Yellow, Green,
   Darker[Green], Cyan, Blue, Purple, Black, Gray};
names = Table["Color " <> ToString[i], {i, 1, Length[colors]}];

table[pairs_] := TableForm[pairs, TableAlignments -> Left,
   TableSpacing -> {2, 1}];

LineLegend[colors[[;; 11]], names, LegendLayout -> table, 
 LabelStyle -> {20, FontFamily -> "Arial"}]

enter image description here

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108