3
$\begingroup$

I would like to know how to reduce the vertical spacing between the legends in the PlotLegend option.

In the answer to this similar question in How to change the spacing of line in legend? it suggests using the option "Spacings" in the method LineLegend. However, such an option seems to be abandoned at least in version 12.0, so what would be the way to achieve the same goal similar to the Spacings option now?

$\endgroup$
2
  • 2
    $\begingroup$ For v12.2.0, the option Spacings shows up in Red and the popup says: Spacings is not an option for LineLegend; but somehow it still works. $\endgroup$
    – Syed
    Commented Jun 7, 2022 at 8:44
  • $\begingroup$ Crossposted here. $\endgroup$ Commented Jun 7, 2022 at 22:00

1 Answer 1

2
$\begingroup$

One way is to give a function to the LegendLayout option. The following is an example of using Column[list,alignment,spacing]. The list itself uses Row[] to combine the colored line (or swatch if SwatchLegend[] is used) with the expression, while spacing controls the vertical spacing. The position of the legend itself is controlled by Placed[].

Plot[{Sin[x], Cos[x]}, {x, 0, 5}, 
 PlotLegends -> 
  Placed[
   LineLegend["Expressions", 
    LegendLayout -> (Column[(Row[{#1[[1]], " ", #1[[2]]}] &) /@ #, 
        Left, 0.5] & )], {1, 0.8}]]

enter image description here

$\endgroup$

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.