Home | News | Documentation | Download

TLegend set distance between entry symbol and entry text


#1

Hi,

I am trying to adjust the distance between an entry symbol (i.e. the marker, line, filled box, etc.) and its text in TLegend independent of its margin (i.e. its width). Is this possible somehow?

Cheers,
Ben


#2

What can be set regrading legend geometry is summarise by this example legendgeometry.C (1.4 KB)


#3

Thank you for this clarification. I deduce that it is not possible directly via ROOT. The workaround I am using with pyROOT is

legend = TLegend()
hist = TH1()

entryOption = 'P'
entryTitle = '#kern[-0.2]{ }' + hist.GetTitle()
legend.AddEntry(hist, entryTitle, entryOption)

By adapting the number in the kern, you can adapt the space between the symbol and the text.

Cheers,
Ben


#4

Of course the same can be done using C++. For instance:

   auto legend = new TLegend(...);
   auto hist = new TH1(...);
   legend->AddEntry(hist, Form("#kern[-0.2]{ } %s ",hist.GetTitle()), "P");