0
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}}]]] 

enter image description here

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

MMA13
  • 4,664
  • 3
  • 15
  • 21
  • 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. – user293787 Jul 07 '22 at 08:25
  • thanks for the comment, I updated the question – MMA13 Jul 07 '22 at 08:41
  • 1
    add the option Spacings -> {.5,.3} (replace {.5, 3} with your choice) in LineLegend? – kglr Jul 07 '22 at 12:14
  • @kglr that is exactly what looking for..Thanks a lot! – MMA13 Jul 07 '22 at 13:15

2 Answers2

1

Based on this answer you could try to replace

ToString[#] &

by something like

Framed[ToString[#],
       FrameStyle->None,
       FrameMargins->{{-5,-5},{0,0}},
       ContentPadding->False] &
user293787
  • 11,833
  • 10
  • 28
1

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:

enter image description here

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96