Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I prefer a sans serif font in graphics, which I do by creating a style for "Graphics" in a stylesheet. However, this does not affect the style used by legend labels:

Plot[{x, 2x}, {x, 0, 1}, PlotLegends -> {"Times", "New Roman"}]

enter image description here

Is there any way to change the legend text style in the stylesheet, or can it only be done through the LabelStyle option?

share|improve this question
    
In prior versions legending was handled by a series of accessible functions that could be modified, e.g. (4586) -- have you done any "spelunking" in v9(+) to see what might be done? –  Mr.Wizard Jun 7 at 13:29
    
@Mr.Wizard, I had a look but couldn't see where the explicit font setting was applied. I think it must be somewhere in MakeBoxes. –  Simon Woods Jun 7 at 14:50

2 Answers 2

up vote 3 down vote accepted

It seems to me the answer is no. If you look at the box structure your plot creates, you will see it handles the legend with TemplateBox.

If the tag of the TemplateBox is a string, then that style will be used for the TemplateBox.

The problem is that these TemplateBox instances specify the DisplayFunction explicitly, which will override a stylesheet.

EDIT (Per OP's comment.)

However, to the extent that a DisplayFunction does not contradict the stylesheet specifications, those specifications will apparently persist. In this case, then, the problem is that the DisplayFunction specifies the FontFamily, which will always trump the stylesheet.

share|improve this answer
    
For me the TemplateBox tag is a string, so I tried creating a named style for LineLegend. It turns out the legend will pick up the font size, weight and colour from the stylesheet but not the font family. Looking at the boxes, the Times font is explicitly specified in a StyleBox which overrides the style from the stylesheet :-( So I think you are right, I will have to set the LabelStyle option in the kernel. –  Simon Woods Jun 6 at 20:38
    
@SimonWoods Oops, I get a string tag too. I was thinking in kernel mode (i.e., should be "\"LineLegend\""); glad you caught that :) –  mfvonh Jun 6 at 21:06
Plot[{x, 2 x}, {x, 0, 1}, PlotLegends -> {Style["Times", FontFamily -> "Times"], Style["New Roman", FontFamily -> "New Roman"]}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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