Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
2  
f[pairs_] := Grid[pairs]; LineLegend[colors, names, LegendLayout -> f, LabelStyle -> {20, FontFamily -> "Arial"}] gives !Mathematica graphics – Nasser Apr 12 '14 at 17:09
up vote 6 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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