# How can we control the space between two successive legends and between label and legend?

Block[{const = {2.2, 3.1, 3.5}},
plt0 = ListLinePlot[
Table[{x, Sin[x #]}, {x, 0, 10, 0.05}] & /@ {1, 2, 3},
PlotRange -> {{0, 10}, {-1, 1}}, FrameLabel -> {"X ", "Y"},
PlotRangeClipping -> False, Frame -> True, ImagePadding -> 50,
PlotLegends ->
Placed[LineLegend[{ToString[#] & /@ const},
LegendLayout -> {"Row", 1},
LegendMarkerSize -> 8], {{0.5, 0.5}, {0.5, -3}}]]]


Is it possible to control the space indicated by the red arrows and make it smaller?

• It would be good to provide a minimal example. This is a question about LineLegend I think, so why not make a very simple plot with only the option that causes problems? Also, you use MaTeX which is not available by default in Mathematica. Jul 7, 2022 at 8:25
• thanks for the comment, I updated the question Jul 7, 2022 at 8:41
• add the option Spacings -> {.5,.3} (replace {.5, 3} with your choice) in LineLegend?
– kglr
Jul 7, 2022 at 12:14
• @kglr that is exactly what looking for..Thanks a lot! Jul 7, 2022 at 13:15

Based on this answer you could try to replace

ToString[#] &


by something like

Framed[ToString[#],
FrameStyle->None,
FrameMargins->{{-5,-5},{0,0}},


The distance between the line and the figure one can control by placing the empty space after the quote: "2.2", " 2.2" or " 2.2". The space between two different legends one can also enter as white space, or alternatively by using Spacer. As an example, I give below two images with different spacings:

Column[{
Block[{const = {2.2, 3.1, 3.5}},
plt0 = ListLinePlot[
Table[{x, Sin[x #]}, {x, 0, 10, 0.05}] & /@ {1, 2, 3},
PlotRange -> {{0, 10}, {-1, 1}}, FrameLabel -> {"X ", "Y"},
PlotRangeClipping -> False, Frame -> True, ImagePadding -> 50,
PlotLegends ->
Placed[LineLegend[{"2.2" Spacer[10], "3.1" Spacer[10],
"3.5" Spacer[10]}, LegendLayout -> {"Row", 1},
LegendMarkerSize -> 8], Scaled[{0.5, 1.01}]],
ImageSize -> 300]],

Block[{const = {2.2, 3.1, 3.5}},
plt0 = ListLinePlot[
Table[{x, Sin[x #]}, {x, 0, 10, 0.05}] & /@ {1, 2, 3},
PlotRange -> {{0, 10}, {-1, 1}}, FrameLabel -> {"X ", "Y"},
PlotRangeClipping -> False, Frame -> True, ImagePadding -> 50,
PlotLegends ->
Placed[LineLegend[{"  2.2" Spacer[10], "  3.1" Spacer[10],
"  3.5" Spacer[10]}, LegendLayout -> {"Row", 1},
LegendMarkerSize -> 8], Scaled[{0.5, 1.01}]],
ImageSize -> 300]]
}]


returning the following: