# Can I change Legend text in a stylesheet?

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"}]


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

• 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 '14 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 '14 at 14:50

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.

• 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 '14 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 '14 at 21:06
Plot[{x, 2 x}, {x, 0, 1}, PlotLegends -> {Style["Times", FontFamily -> "Times"], Style["New Roman", FontFamily -> "New Roman"]}]