Placing TLatex textbox in canvas

Hi,

I am using Tlatex for writing some text in my canvas, and dont find it very practical to place the text according to the coordinates of the plot. I would rather like to place it just in relation to the canvas, say in the same way as I do the legend. Is there a way to do this? Alternatively another kind of text class that gives me this possibility?

Right now I am doing e.g.


Float_t ymin=hratio->GetMinimum();
  Float_t ymax=hratio->GetMaximum();
  Float_t xmin=hratio->GetBinLowEdge(1);
  Float_t xwidth=hratio->GetBinWidth(1);

  sprintf(TextBox,"some text");
  tex = new TLatex(xmin+xwidth/2,0.6,TextBox);
   tex->Draw();

where hratio is a histogram.

Thank you very much.

Example:

{
   TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
   h1->FillRandom("gaus",20000);
   h1->SetFillColor(kRed);
   h1->Draw();
   TLatex t(-3,500,"TLatex at (-3,500)");
   t.Draw();
}

Thank you for the example, maybe I was not clear.

This give me the box at the coordinates x=-3, y=500. What I want instead, is to place the text box relative to the pad, not the coordinates, as I am plotting many different plots with different coordinates, but want the text placed, let’s say in the lower left corner of the pad.

Is this possible?

Thank you very much.

{
   TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
   h1->FillRandom("gaus",20000);
   h1->SetFillColor(kRed);
   h1->Draw();
   TLatex t(.1,.1,"TLatex at (.1,.1)");  
   t.SetNDC(kTRUE);
   t.Draw();
}

I must be very unclear today. :slight_smile:

I want to place the text box without having to depend on the coordinates. Sometimes the lower left corner has coordinates x=10, y=10, othertimes it can have x=1, y=0.5 or whatever. But I still want to make a macro that places the textbox relative to the pad and not the axis coordinates… Just like I can place a legend relative to the pad itself. The pads upperleft corner is e.g. x=0, y=1 , while the upper right corner is x=1, y=1.

Get my point?

Thank you again!!

Yes , I didnt spot the command

t.SetNDC(kTRUE);

that did the trick. Thank you ever so much!!

Regards
Maiken

Note that in the recent ROOT versions DrawLatexNDC is implemented.