Use differnt colors for different text lines in a TPaveText

Dear ROOTers,
I would like to use differnt colors for different text lines in a TPaveText, is it possible?
I mean something like:

TPaveText::AddText(const char* label, Color_t fcolor)

If not which is the best workaround?

Thank you,
Leonardo

Try this:

TPaveText* t = new TPaveText(0.782,0.821,0.892,0.879,"brNDC");
t->AddText("abc"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(1);
t->AddText("def"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(2);
t->Draw();

Good point. I have improved the doc and tutorials to illustrate this. The example in tutorials is now:

{
   TCanvas *c = new TCanvas("c");
   TPaveText *pt = new TPaveText(.05,.1,.95,.8);

   pt->AddText("A TPaveText can contain severals line of text.");
   pt->AddText("They are added to the pave using the AddText method.");
   pt->AddLine(.0,.5,1.,.5);
   pt->AddText("Even complex TLatex formulas can be added:");
   pt->AddText("F(t) = #sum_{i=-#infty}^{#infty}A(i)cos#[]{#frac{i}{t+i}}");

   pt->Draw();

   TText *t = pt->GetLineWith("Even");
   t->SetTextColor(kOrange+1);

   return c;
}

It will be visible in the online doc tomorrow.

@ferhue:

Good example also. I added it in the doc too. (visible tomorrow)/

how about something even simpler:

TPaveText* p = new TPaveText(0.782,0.821,0.892,0.879,"brNDC");
TText * t = p->AddText("aaa");
t->SetTextColor(kRed);
t->Draw()
t = p->AddText("bbb");
t->SetTextColor(kGreen);
t->Draw();

Otto

1 Like

Hi Otto,
Yes you have a good point. I added this way in the example.