Start Legend neatly from top

Consider this case:

int legend()
{
  TCanvas * c1 = new TCanvas;
  TCanvas * c2 = new TCanvas;
  TH1 * h = new TH1F("h", "h", 5, 0.0, 5.0);
  h -> FillRandom("gaus", 500);
  TLegend * legend1 = new TLegend(0.6, 0.6, 0.95, 0.95);
  TLegend * legend2 = new TLegend(0.6, 0.6, 0.95, 0.95);
  legend1 -> AddEntry(h);
  legend1 -> AddEntry(h);

  legend2 -> AddEntry(h);
  legend2 -> AddEntry(h);
  legend2 -> AddEntry(h);

  c1 -> cd();
  h -> Draw();
  legend1 -> Draw("SAME");

  c2 -> cd();
  h -> Draw();
  legend2 -> Draw("SAME");

  c1 -> SaveAs("c1legend.png");
  c2 -> SaveAs("c2legend.png");
  return 0;
}


Please read tips for efficient and successful posting and posting code
How can I start legend neatly from top and use a fixed font size?
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


So, what is the problem ?

I think it’s about the font size, which changes “automatically” because one has to set the legend’s dimensions “manually”.

I guess the idea would be to set some “fixed” font size “manually” and then the legend would calculate its dimensions “automatically”.

I would like the legend entries started neatly from top, not auto dispersed to cover the whole legend area.

The legend entries are drawn equally spaced within the legend box size you defined.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.