Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Text Mesh Pro text does not center properly on the Y-axis

Discussion in 'UGUI & TextMesh Pro' started by mdentonetc, Oct 28, 2022.

  1. mdentonetc


    Jul 23, 2012
    I've noticed that when I use Text Mesh Pro fonts and attempt to have things centered on the border of the text field and have the alignment set to Middle vertically it is always a little bit above center. I didn't have this issue with standard Unity UI text. I'm wondering if there's a standard fix for this.

    At the moment I just always adjust the Pos Y or Tio Rect Transform value to be something like -2. But it feels like I shouldn't have to do this to make fonts centered.

  2. karliss_coldwild


    Oct 1, 2020
    Vertical centering of text is not a clearly defined problem with single universally applicable solution. Depending on your usecase you might want to play with the lest 3 modes in the alignment settings, in some cases some manual tweaking is unavoidable.


    Vertical dimensions of text consist of minimum 4 different horizontal lines (in reality probably more, if you open the settings for font asset you will see more than dozen different heights and vertical offsets.) Which two of them do you use for defining vertical center of text? Do you align based on dimensions of typical lowercase letter like oooooo? What if you addd capital letters oooAAAA? What if you add letters that go bellow baseline like oooAAAjjj? What if you add charcters with diacritics oooAAAjjjĀĀ? What if you add second level of diacritics oooAAAjjjĀĀǞ? What if you add underline bellow text oooAAAjjjĀĀǞ, should that be taken into account when centering vertically? How often are those symbols going to appear in text? Is it a text in English with almost no diacritics, or is it text in language where almost every word contains some? Is it a long text or single word in header or logo? How should something like be centered? Choosing optimal centering for one of the cases will look worse in other. You could also center based the pixel boundaries of currently visible characters (which is what I think second from last mode does) but that has the downside of text potentially jumping up and down as you add more characters with different heights. There may also be case where it looks visually more pleasing and balanced if you do the centering based on most common character height ignoring the one or two character which are higher than the rest. To make things worst not all the fonts define all of those heights correctly and consistently. Is there going to be second UI element placed next to the current one using same font but different text and you want them to be aligned to each other?

    Only you can answer to all of those questions and choose the tradeoffs that suit your use case.
    Strom_CL likes this.