# Words are not horizontally aligned in word-by-word display

**URL:** <https://psychtoolbox.discourse.group/t/words-are-not-horizontally-aligned-in-word-by-word-display/5424>\
**Category:** Programming Help\
**Created:** [July 10, 2024, 12:09pm UTC](https://psychtoolbox.discourse.group/t/words-are-not-horizontally-aligned-in-word-by-word-display/5424 "2024-07-10T12:09:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zrhuang](https://avatars.discourse-cdn.com/v4/letter/z/ecae2f/32.png) [@zrhuang](https://psychtoolbox.discourse.group/u/zrhuang)\
**Post date:** [July 10, 2024, 12:09pm UTC](https://psychtoolbox.discourse.group/t/words-are-not-horizontally-aligned-in-word-by-word-display/5424/1 "2024-07-10T12:09:48Z")

</div>

Hi everyone!  
I am trying to present the words in sentences word-by word at the centre of the screen. it works well but I noticed that the centred words are not horizontally aligned because the text bounds are different for words (e.g, “one” and “fog” have different heights) so when display words at the centre, it looks like the words are jumping around.  
So how I can fix the problem to make the words are aligned at the letter bottom line?  
I am also attching the current function for drawing centred text here.  
Many thanks in advance!

```auto
function drawcenteredtext_dot(w,str,x,y,color,textsize)

str=double(str);
oldsize=Screen('TextSize',w,textsize);
drect=Screen('TextBounds',w,str);

sx=x-drect(3)/2;
sy=y-drect(4)/2;
Screen('DrawText',w,str,sx,sy,color);
Screen('TextSize',w,oldsize);

```

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 17, 2024, 6:03pm UTC](https://psychtoolbox.discourse.group/t/words-are-not-horizontally-aligned-in-word-by-word-display/5424/2 "2024-07-17T18:03:07Z")

</div>

I’m not sure what you mean by not horizontally aligned, given that only one word is shown in each image as far as I understand your task, but if you meant “not vertically at the same height”, ie. it is jumping up and down a bit depending on the word and the height of the letters in it, that is what functions like DrawFormattedText() are for, cfe. DrawFormattedTextDemo.m. Or use of the ‘yPositionIsBaseline’ flag in Screen DrawText to make sure that y position specifies the vertical baseline position of the text, instead of the top position of the tallest glyph.
