4
$\begingroup$

There's a Plot whose legend has symbols with subscripts and regular text. The words that have subscripts appear to shrink in size and looks out of place in comparison to the rest of the legend.

Was looking up, and it doesn't seem like I can have different sizes inside a string.

In general I use FrameLabel defined like this for the legends

Style["\!\(\*SubscriptBox[\(t\), \(2g\)]\)  Element", FontFamily -> "TeX Gyre Pagella",  FontSize -> 22]

Is there a way I could have \!\(\*SubscriptBox[\(t\), \(2g\)]\) in font size 26 and the rest in 22? StringJoin doesn't work and I am unsure what type of thing Style is.

Thought it could work with Graphics, but at least how I tried it doesn't seem to work. My idea was to create a GraphicsRow with the two different texts of different sizes.

plot1=Plot[x^2, {x, 0, 3} , Frame -> True];
tex1 = Style["Element ", FontSize -> 22, FontFamily -> "TeX Gyre Pagella"];
tex2 = Style["\!\(\*SubscriptBox[\(e\), \(g\)]\)    Element", FontSize -> 22, FontFamily -> "TeX Gyre Pagella"];
tex3 = Style["\!\(\*SubscriptBox[\(e\), \(g\)]\)", FontSize -> 26, FontFamily -> "TeX Gyre Pagella"];
legend1 = GraphicsRow[{tex2}]
legend2 = GraphicsRow[{tex3, tex1}]


Legended[ Show[ plot1, ImageSize->850,PlotRange->{{0.1, 1.02},{-0.05,5.3}}, 
Epilog ->  {Directive[{Black, Dashing[0.02]}],Line[{{0.820,0},{0.820,6}}]},
Prolog-> Inset[Style[inset,Magnification>0.6], Scaled[{0.25,0.76}], Scaled[{0.5,0.5}], Scaled[{1,1}]]], 
Placed[LineLegend[{Directive[Black, Magnification->3.5], Directive[Red, Magnification->3.5]}, {legend2,legend2}], Scaled[{0.58, 0.16}]]]

The legend has a lot of extra vertical space because of GraphicsRow but it does allow me to have a higher font size for the words with subscripts. Is there a way to remove the vertical white space?.

Honestly I didn't know what I was doing, was just trying to solve the issue but I dont really know. Can it be done? Is there an actual way to get it without huge extra vertical space?

Thanks to anyone who can help and for reading.

$\endgroup$

1 Answer 1

7
$\begingroup$

You can wrap Styled objects with ToString[#, StandardForm]& and StringJoin them:

StringJoin[
  ToString[Style[Subscript[t, 2 g], 48, FontFamily -> "Lucida Handwriting"], StandardForm],
  ToString[Style[" Element", 32, Red, FontFamily -> "Old English Text MT"], StandardForm]]

enter image description here

Alternatively, you can combine elements with different styles using Row:

Row[{Style[Subscript[t, 2 g], 48, FontFamily -> "Lucida Handwriting"],
   Style[" Element", 32, Red, FontFamily -> "Old English Text MT", 
    ShowStringCharacters -> False]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you! You learn something new every day :) $\endgroup$
    – M.O.
    Commented Dec 15, 2018 at 16:17

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.