LaTeX in a graph


 I would like to place a D0 Preliminary quote on one of my graphs.   I looked around and found the following...
  TLatex *text = new TLatex();
  text->DrawTextNDC(0.12, 0.14, "D0 Preliminary");

Unfortunately this seems to not honor LaTeX commands cause what I really need it to be is the following…

  TLatex *text = new TLatex();
  text->DrawTextNDC(0.12, 0.14, "D#slash{0} Preliminary");

Can anybody explane to me why the second code chunk does not work and how I might be able to get that zero with a slash on it in my plot? Thanks for any info.

I think that the root version that I am using at D0 is 4.04 and the local install on my laptop is 5.12.


D#slash{0} was not implemented in version 4.04. You have to move to a more recent version.


I have the same problem when using 4.04 and 5.12… When was the #slash implemented?

I am now leaving for a trip. Olivier will process your mail on Monday


TLatex inherits from TText. So you can use all the TText methods on a TLatex. DrawTextNDC is one of them. But if you use it a TLatex will be consider as a TText and the TLatex directives will not be interpreted. Use DrawLatex instead.

I was going to use that but there is no NDC style method for the DrawLatex…

Can you try “SetNDC” on that text ?

Note that in more recent ROOT version DrawLatexNDC is implemented.

To make this clear for other users (like me) who are searching for an answer:

If you want to draw a latex label but in NDC coordinates you have to do:

TLatex tt1 = TLatex(); tt1.SetNDC(); tt1.DrawLatex(0.17, 0.21, "#sqrt{s} = 7 TeV");
because there is no DrawLatexNDC(), but doing SetNDC() lets you do it.

Actually the example given here was more explicit:


I used

TLatex T1;
T1.DrawLatexNDC(.05, .95, “#sqrt{s}=14 TeV, #int Ldt=300 fb^{-1}”)

It works in 5.34, but I cannot find how to change the title size. Top of the integral sign is outside the canvas. When I lower it, it enters into the histogram. Please help me about this issue.


Send a more complete example showing the whole picture. I will then show you the needed adjustements.

I uploaded the whole file since I am not sure which part you need.

Thank you,
50PU_root.C (3.72 KB)

Send me something I can run… I do not have the files:

   TFile *bkg1 = TFile::Open("SingleS_P+MET_50PU_TopJets_mt2w_his.root");
   TFile *bkg2 = TFile::Open("SingleS_P+MET_50PU_TTbar_mt2w_his.root");
   TFile *bkg3 = TFile::Open("SingleS_P+MET_50PU_DiBoson_mt2w_his.root");
   TFile *bkg4 = TFile::Open("SingleS_P+MET_50PU_BosonJets_mt2w_his.root");
   TFile *sgnl4 = TFile::Open("SingleS_P+MET_50PU_TDR4_mt2w_his.root");
   TFile *sgnl5 = TFile::Open("SingleS_P+MET_50PU_TDR5_mt2w_his.root");
   TFile *sgnl6 = TFile::Open("SingleS_P+MET_50PU_TDR6_mt2w_his.root");
   TFile *sgnl8 = TFile::Open("SingleS_P+MET_50PU_TDR8_mt2w_his.root");

Just make a simplified version of your macro.

Sorry, here they are.
50PU_root.C (1.33 KB)
SingleS_P+MET_50PU_TopJets_mt2w_his.root (14.7 KB)


   // Create a histograms and stack
   THStack *hs1 = new THStack("hs1","");
   TH1F* JetPt_50PU_TopJets;

   TFile *bkg1 = TFile::Open("s.root");
   JetPt_50PU_TopJets= (TH1F*) bkg1->Get("hJetPt");

   TFile* file = new TFile ("stack_JetPt_50PU.root","RECREATE");
   TCanvas* c1 = new TCanvas("c1","stack_JetPt",800,20,1000,800) ;



   TLatex T1;
   T1.DrawLatexNDC(.06,.90, "Delphes samples #sqrt{s}=14 TeV, #int Ldt=300 fb^{-1}");


   hs1->GetXaxis()->SetRangeUser(0, 600);
   hs1->GetHistogram()->GetXaxis()->SetTitle("P_{T} [GeV]");
   hs1->GetHistogram()->GetYaxis()->SetTitle("Events/20 GeV");

   TLegend *pl = new TLegend(0.7, 0.6, 0.9, 0.8);
   pl->AddEntry(JetPt_50PU_TopJets, "TopJets JetPt 50PU",  "lpf");


Thank you very much for your solution. It works, but do you have any option for the font size of the title. It is still too big. I saw some papers that do it.

Thanks again,

see for all the details about text attributes.

Sorry but it doesn’t work. Nothing changes when I include SetTextSize.

Thank you,

Yes It works:

   TLatex T1;
   T1.DrawLatexNDC(.06,.90, "Delphes samples #sqrt{s}=14 TeV, #int Ldt=300 fb^{-1}");

Ok, it works now.

I did put it below the DrawLatex. I think that is the reason.

Thank you very much for your help,