Problem with position of TLatex objects in canvas

I wrote a very small macro to do a horizontal calendar and I’ve noticed that the numbers that are placed for the days are placed at locations that seem to not be aligned (even though, of course, the X and Y positions are perfectly and correctly defined in the script). The result is this:

Screen Shot 2023-01-23 at 21.01.06

The code to reproduce this is semi-trivial:

calendar-horizontal.C (2.9 KB)

I am wondering how to fix the misalignment. Is there perhaps some internal precision of some sort that. could tweak? In fact, it makes me kind of weary about ROOT’s drawing precision in general, I have to admit…

Thanks for any and all help!

ROOT Version: ROOT 6.24/06
Platform: Mac OS X 10.15.6
Compiler: Not Provided


So, switching the text alignment to 21 and offsetting the result vertically removes the imprecision completely. It must be something related to the vertical auto alignment going slightly off… Anyway, from my side this is solved but the underlying issue is not really solved I guess…

Try with TText instead of TLatex; simply substitute the string Latex → Text in your code (6 instances).
The way TLatex is aligned seems not optimal, but the developers can comment on that :slight_smile:

I do not see this effect either with TText or TLatex:

void align2() {
   auto tt = new TText();
   tt->SetTextAlign(22);
   tt->SetTextSize(0.3);
   tt->DrawText(.1,.5,"17");
   tt->DrawText(.3,.5,"18");
   auto tl = new TLatex();
   tl->SetTextAlign(22);
   tl->SetTextSize(0.3);
   tl->DrawText(.5,.5,"17");
   tl->DrawText(.7,.5,"18");
   auto l = new TLine();
   l->DrawLine(0.,0.5,1.,0.5);
   l->DrawLine(0.,0.39,1.,0.39);
   l->DrawLine(0.,0.59,1.,0.59);
}

Try this:

 {
   auto tt = new TText();
   tt->SetTextAlign(22);
   tt->SetTextSize(0.3);
   tt->DrawText(.1,.5,"3");
   tt->DrawText(.3,.5,"17");
   auto tl = new TLatex();
   tl->SetTextAlign(22);
   tl->SetTextSize(0.3);
   tl->DrawText(.5,.5,"3");
   tl->DrawText(.7,.5,"17");
   auto l = new TLine();
   l->DrawLine(0.,0.5,1.,0.5);
   l->DrawLine(0.,0.392,1.,0.392);
   l->DrawLine(0.,0.6,1.,0.6);
}

It actually starts to show something for both TText and TLatex; it seems to depend on the numbers, and maybe other factors (even in your example, the 8 is slightly larger and below the lower line).

It gives me:

Yes, the coordinates seem a little off (maybe in my case, using WSL), but still your 3s are lower, as they go slightly below the line (even if the tops match), while 17 is on the line; if you lower a bit the horizontal lines to match the bottom and top of the 3 you should see the same I get. In any case, the “calendar” macro clearly shows the issue more dramatically, I don’t know if it’s additionally affected by the many changes in coordinates and text size, but I tried a few modifications and always got the same problem, until I changed to TText. It looks like the numbers are not the same size (height), so they may be aligned at the centre but some just have more (or less) pixels.

I am afraid we cannot do better than that. All the text placement is done using freestyle. I might be that because of more computation with TLatex you get this effect.

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