How to vertically align text in a RichTextLabel?

:bust_in_silhouette: Reply From: Reneator

Update: Labels now have an autowrap setting. Setting a label to expand in size-flags and deactivate the shrink. When now setting the align and valign as centered could have the same result as the description below.

I know this is an old post, but may have found a simpler solution (Maybe it didnt exists in the older versions. currently using 3.2.3.stable):

Im doing this inside of a PanelContainer, but think should work for other containers as well.

By activating “Fit Content Height” the RichTextLabel will resize itself to properly show the content inside itself.

Then in the Size Flags i deactivate the Vertical Fill, so that the RichTextLabel doesnt fill the entire container.

I activate the Size Flag “Vertical - Shrink Center” so the RichTextLabel gets aligned in the vertical center. And due to the “Fit content Height” the RichTextLabel doesnt get squished to zero height, so no need to work with min-size here.

And the Text should now be centered vertically!

You can test this best with like one or two words and a bigger panel. If the line-count is too big,the richtextlabel will automatically fill the container its in and push outwards.

Oh wow it works perfectly! Thank you very much!

Zero | 2022-02-08 21:05

2 Likes