Changing the legend font using TStyle

I’m creating an experiment-wide TStyle to distribute and don’t trust users to create consistent plots with anything more than activating our custom style. I’m having trouble creating TLegends that inherit the correct font from gStyle. (ROOT 5.32/00). I’ve used font 142 to highlight what is and isn’t changed.

[code]{
TStyle *alpha = new TStyle(“alpha”,“Alpha Style”);

Int_t font = 142;

alpha->SetLegendFont(font);
alpha->SetLabelFont(font, "xyz");
alpha->SetTitleFont(font, "xyz");
alpha->SetTitleFont(font, "");
alpha->SetLabelFont(font, "");
alpha->SetStatFont(font);

alpha->cd();

TH1F *hTemp = new TH1F("hTemp", "hTemp;Axis 1;Axis 2", 50, -5, 10) ;
hTemp->FillRandom("gaus");
hTemp->Draw();
TLegend *legend = new TLegend(.5, .35, .98, .65, "Title");
//legend->SetTextFont(gStyle->GetLegendFont());
legend->AddEntry(hTemp,"Temp");
legend->Draw();

}[/code]

This will create the following canvas:


Uncommenting the “SetTextFont” line produces the following:


So there are two issues. First, the legend doesn’t seem to inherit the gStyle font. Second, even when setting it by hand, the title of the legend isn’t changed (although another post indicates you can create the legend without a title, change it’s font manually, then SetHeader and it has the correct font which does check out, but again I don’t trust users to submit plots with correct fonts if this is needed).

Switch to ROOT 5.34.
See: [url]Changing fonts in TLegend via gStyle

If not possible, see: [url]TLegend header's font size

(BTW. Try to “Search…” the forum for “SetLegendFont” and/or any other “magic words” -> that’s how I found the first link in which one explicitly says you need a new version of ROOT.)

Thanks Pepe. I read through that post but since the thread started in 2007 I figured that the changes had been made and undone somewhere along the way.

If only I had noticed when one of the later responses said updates were pushed to the SVN trunk (rather than the CVS head mentioned in Rene’s first response) I would have realized those were recent additions and wouldn’t have wasted your time.

Until the collaboration agrees to upgrade to 5.34, I’ll publicize the work-around. Thanks again.