# TText, SetTextAlign

**URL:** <https://root-forum.cern.ch/t/ttext-settextalign/26042>\
**Category:** ROOT\
**Created:** [August 28, 2017, 11:37am UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042 "2017-08-28T11:37:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lawlieto](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lawlieto/32/13455_2.png) [@lawlieto](https://root-forum.cern.ch/u/lawlieto)\
**Post date:** [August 28, 2017, 11:37am UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/1 "2017-08-28T11:37:11Z")

</div>

Dear ROOTers,

I’m having an issue with aligning my text on a canvas. The text I created overlaps with the picture itself, and I’d like to move the text **upwards** so that both the picture and the text could be seen properly. Currently I’m using t-\>SetTextAlign(31), and I’ve tried a few other numbers, but those were even worse.

Any ideas how to move the text upwards?  
I attached the picture  
Thanks!

 ![08](https://root-forum.cern.ch/uploads/default/original/2X/7/71bf29327d01e1cb1af7739ff714ec2a827aad8a.png)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 28, 2017, 12:47pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/2 "2017-08-28T12:47:46Z")

</div>

Try with [TText::PaintText](https://root.cern.ch/doc/master/classTText.html#a870a549d00966b68c8bbecd6a0e7edbc) or [TText::PaintTextNDC](https://root.cern.ch/doc/master/classTText.html#a7936a1ca29cce598952c5d891f09fcdf)

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 2:16pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/3 "2017-08-28T14:16:39Z")

</div>

A small example would be allow us to be more helpful to you. Which text class are you using: [`TText`](https://root.cern.ch/doc/master/classTText.html), [`TLatex`](https://root.cern.ch/doc/master/classTLatex.html), [`TMathText`](https://root.cern.ch/doc/master/classTMathText.html), [`TPaveText`](https://root.cern.ch/doc/master/classTPaveText.html), …?

You might just want [`TText::SetX`](https://root.cern.ch/doc/master/classTText.html#aa62dca3af3989a1790599304b41c649b) or [`TText::SetY`](https://root.cern.ch/doc/master/classTText.html#a5160c6cd079e4dd93afff6650898af2b)?

---

<div class="post-metadata">

**Author:** ![lawlieto](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lawlieto/32/13455_2.png) [@lawlieto](https://root-forum.cern.ch/u/lawlieto)\
**Post date:** [August 28, 2017, 3:01pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/4 "2017-08-28T15:01:10Z")

</div>

I’m using TText, and this is part of my code:  
cdate is a const char.  
TText\* t = new TText(.5,.5,cdate);  
t-\>SetTextAlign(31);  
t-\>SetTextColor(kBlue);  
t-\>Draw();

I’ll try to use SetX and SetY

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 3:06pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/5 "2017-08-28T15:06:24Z")

</div>

Why not just change the position in the constructor?

```auto
TText* t = new TText(.5,.1,cdate);
t->SetTextAlign(31);
t->SetTextColor(kBlue);
t->Draw();

```

Just FYI:

> [@Getting the same histograms after cuts](https://root-forum.cern.ch/t/getting-the-same-histograms-after-cuts/24719/2):
>
> Remark on the way to post code snippets: When you post pieces of code on the forum enclose it with ``` . That makes your post much more readable (I systematically edit your posts that way) . So do: ``` // this is a C++ piece of code. ``` And it will display as: // this is a C++ piece of code.

---

<div class="post-metadata">

**Author:** ![lawlieto](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lawlieto/32/13455_2.png) [@lawlieto](https://root-forum.cern.ch/u/lawlieto)\
**Post date:** [August 28, 2017, 3:20pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/6 "2017-08-28T15:20:58Z")

</div>

Because I didn’t know that input stood for the position 😂  
Thanks a lot! 🙂 and thank you for the advice about formatting my posts

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 3:25pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/7 "2017-08-28T15:25:10Z")

</div>

You’re welcome. Here is the brief documentation on the constructor for future reference:  
[https://root.cern.ch/doc/master/classTText.html#a0cb6bb845e458e61dc2415f5b432bc93](https://root.cern.ch/doc/master/classTText.html#a0cb6bb845e458e61dc2415f5b432bc93)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [September 11, 2017, 3:25pm UTC](https://root-forum.cern.ch/t/ttext-settextalign/26042/8 "2017-09-11T15:25:19Z")

</div>

Closed on September 11, 2017, 3:25pm UTC

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