How can I make a background for legend like this?
It's not necessary to be exact the same but something similar that fits the content is good. Or please suggest if you have any idea to make it look better.
I'm going to put it inside some plot with grids that is why I need the background to make it better.
I also need to make the background fits the content.
ClearAll[legend1]
Options[legend1] = {Joined -> Automatic};
legend1[colors_, polymarkers_, legend__, , OptionsPattern[]] :=
PointLegend[colors, legend, Joined -> OptionValue[Joined],
LegendMarkers -> (ResourceFunction["PolygonMarker"][#, Offset[4],
EdgeForm[]] & /@ polymarkers), LegendMarkerSize -> {30, 30},
LegendLayout -> (Column[
Grid[{##}, Alignment -> {Center, Center}] & /@ #,
Spacings -> -1] &)]
colors = ColorData[97, #] & /@ Range[6];
polymarkers = {"DownTriangle", "SevenPointedStar", "FourPointedStar",
"Diamond"};
mylegend =
MaTeX[TeXForm[#], Magnification -> 0.5] & /@ {{"5X", "6Y", "8Z",
"9M", "2K", "2N", "2T", "3N", "5O"}, {"1X", "3Y", "5Z", "2L",
"9K", "3Z", "7X", "3P", "2T"}, {"3K", "6M"}, {"3H", "6K"}, {"X4",
"Y5", "C6", "1K"}, {"X6", "Y6", "C6", "Z6"}};
legend1[colors, polymarkers, mylegend, , Joined -> True]
EDIT: For reference, I'll put the legend in a plot like this.
Legended[Plot[{x, 2 x - 1.5, x - 1, 1 - x, x - 2, 1/2 x - 1}, {x, 1,
5}, GridLines -> {Range[1, 5, 1], Range[1, 5, 1]},
PlotRange -> {{1, 5}, {0, 5}},ImageSize -> 360],
Placed[legend1[colors, polymarkers, mylegend, ,
Joined -> True ], {0.2, 0.8}]]
PointLegend[ ..., LegendFunction -> "Panel"]
? $\endgroup$