5
$\begingroup$

I have the following LineLegend:

Labeled[
 Plot[Exp[-0.03*t], {t, 0, 100}, Frame -> True]
 , LineLegend[{Blue, Green, Red}
  , {"a = test1
    a = test2"
   , "a = test3 
    a = test4", "a = test5 
    a = test6"}
  , LegendLayout -> "Row"
  , LegendMarkers -> {
    {"\[FilledCircle]", 15}, {"\[FilledUpTriangle]", 
     15}, {"\[FilledSquare]", 15}
    }
  ]
 ]

I tried to stack, e.g., a = test1 and a = test2 in a column but keep the overall legend presented as a row by pressing the Enter key between a = test1 and a = test2, but not only did it not work, it seemed like a hacky way of solving the problem.

Is there a way to stack legend item text while maintaining a "Row" layout?

$\endgroup$

1 Answer 1

4
$\begingroup$
Labeled[Plot[Exp[-0.03*t], {t, 0, 100}, Frame -> True]
 , LineLegend[ {Blue, Green, Red},
  {"a = test1\na = test2"
   , "a = test3\na = test4"
   , "a = test5\na = test6"}
  , LegendLayout -> {"Row", 1}
  , LegendMarkers -> {{"\[FilledCircle]", 15}, {"\[FilledUpTriangle]",
      15}, {"\[FilledSquare]", 15}}]
 ]

enter image description here


EDIT

Is there a way to center the marker ...?

I will request you to explore some possibilities.

SeedRandom[1];
Labeled[Plot[Exp[-0.03*t], {t, 0, 100}, Frame -> True]
 , LineLegend[ {Blue, Green, Red},
  Framed[Style[#, RandomColor[]], FrameStyle -> Red] & /@ {
    "a = test1\na = test2"
    , "a = test3\na = test4"
    , "a = test5\na = test6"}
  , LegendLayout -> {"Row", 1}
  , LegendMarkers -> {{"\[FilledCircle]", 15}, {"\[FilledUpTriangle]",
      15}, {"\[FilledSquare]", 15}}
  , LegendFunction -> (Framed[#, RoundingRadius -> 4, 
      FrameStyle -> Darker@Green, Alignment -> Top] &)
  ]
 , Top
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ Is there a way to center the marker to the left of a = test1 and a = test2, as opposed to having it next to a = test1? $\endgroup$
    – MathIsHard
    Commented Apr 19, 2022 at 20:45
  • 1
    $\begingroup$ Please see the update. $\endgroup$
    – Syed
    Commented Apr 20, 2022 at 4:09

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.