3
$\begingroup$

Does anyone know if it is possible within the LineLegend command to have one label for two types of lines? My legend code is here:

CombinedLegend = 
 LineLegend[{White, White, Directive[Black, Thickness[0.001]], 
   Directive[Dashed, Black, Thickness[0.001]]}, {MaTeX[
    "\\alpha_\\theta\\text{ (Numerical)}"], 
   MaTeX["\\alpha_\\phi\\text{ (Numerical)}"], 
   MaTeX["\\text{Theoretical}"], MaTeX["\\text{Theoretical}"]}, 
  LegendMarkers -> {{Graphics[{EdgeForm[{Black, Opacity[1]}], 
   FaceForm[], Disk[]}], 
     0.05}, {Graphics[{EdgeForm[{Black, Opacity[1]}], FaceForm[], 
       Rectangle[]}], 0.05}, None, None}, Spacings -> 0.3]

So I basically want to combine the label for the last two elements into one titled "theory" or something along those lines.

$\endgroup$
2
$\begingroup$

You might need to play a bit with the dimensions etc., but this should get you started:

CombinedLegend = 
 LineLegend[{White, White, White, White},
   {MaTeX["\\alpha_\\theta\\text{ (Numerical)}"], 
   MaTeX["\\alpha_\\phi\\text{ (Numerical)}"], 
   Rotate[MaTeX["\\text{Theoretical}"], 0.05]},
  LegendMarkers -> {
    {Graphics[{EdgeForm[{Black, Opacity[1]}], FaceForm[], Disk[]}], 
     0.05},
    {Graphics[{EdgeForm[{Black, Opacity[1]}], FaceForm[], 
       Rectangle[]}], 0.05},
    {Graphics[{Black, Line[{{0, 0}, {1, 0}}], Dashed, 
       Line[{{0, 0.2}, {1, 0.2}}]}, AspectRatio -> 0.5], 0.05},
    None}, Spacings -> 0.3, LegendMarkerSize -> {10, 10, 40}]

Output: (I don't have the MaTeX package)

enter image description here

The idea is to make a single marker that draws both lines (the size of this double marker is made bigger using the element wise LegendMarkerSize option). Then we can simply do whatever we want to the label (e.g. rotate it accordingly).

$\endgroup$
2
$\begingroup$

You can also use the option LegendLayout with a custom layout function:

gF = Module[{grid = #}, grid[[-1, 2]] = SpanFromAbove; 
    Grid[grid, Alignment -> {Center, Center},  Spacings -> {Automatic, {0, -2 -> -3}}]] &;

CombinedLegend = LineLegend[{Red, Green, Blue, Directive[Orange, Dashed]}, 
{Row[{ToExpression["\\alpha_\\theta", TeXForm],  " (Numerical)"}], 
   Row[{ToExpression["\\alpha_\\phi", TeXForm], " (Numerical)"}], 
   "Theoretical", ""}, "Spacings" -> 0.1, LegendMarkerSize -> 50, 
  LegendLayout -> gF]

enter image description here

Using the example in OP

LineLegend[{White, White, Directive[Black, Thickness[0.001]], 
  Directive[Dashed, Black, Thickness[0.001]]}, 
 {Row[{ToExpression["\\alpha_\\theta", TeXForm],  " (Numerical)"}], 
  Row[{ToExpression["\\alpha_\\phi", TeXForm], " (Numerical)"}], 
  "Theoretical", "Theoretical"}, 
 LegendMarkers -> {{Graphics[{EdgeForm[{Black, Opacity[1]}], 
      FaceForm[], Disk[]}], 0.05}, 
    {Graphics[{EdgeForm[{Black, Opacity[1]}], FaceForm[], Rectangle[]}], 0.05}, 
  None, None}, 
 LegendLayout -> (Module[{grid = #}, grid[[-1, 2]] = SpanFromAbove; 
     Grid[grid, Alignment -> {Center, Center}, 
     Spacings -> {Automatic, {.3, -2 -> -.5}}]] &)]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.