Skip to main content

legending - Changing the inter-item spacing in Legends (version 9 and up)


The legending functionality in versions 9 and higher is much easier to use than the PlotLegends package and other bespoke ways of creating legends in earlier versions. However, the vertical spacing between items is larger than I would like. How can I reduce this spacing?



Changing the LegendMarkerSize option to a smaller number without changing the size specified in the LegendMarkers option just ends up cutting off the graphic. LegendMargins doesn't affect the inter-item spacing, only the space between the whole legend and other items.


PointLegend[{RGBColor[1, 0, 0], RGBColor[0, 0, 1]}, {"Series 1", "Series 2"}, 
LegendMarkers -> {{"\[FilledCircle]", 20}, {"\[FilledCircle]", 20}},
LegendMarkerSize -> 19,
LabelStyle -> {FontFamily -> "Arial", FontSize -> 20}]

enter image description here



Answer



It turns out that the Spacings option does exactly what is needed, even though its use in legend constructs such as PointLegend is not documented, and it shows as red text when you use it in those constructs.


PointLegend[{Red, Blue}, {"Series 1", "Series 2"}, 

LegendMarkers -> {{"\[FilledCircle]", 20}, {"\[FilledCircle]", 20}},
Spacings -> {0.2, 0.2}, LegendMarkerSize -> 19,
LabelStyle -> {FontFamily -> "Arial", FontSize -> 20}]

enter image description here


This continues the tradition of undocumented options and functions in Mathematica.


UPDATE (2): the Spacings option is still marked with red text in version 10.0.1, 10.1 and 10.3 and 11.0.


Comments