View all expressions
Transformation

Auto Align and Center Two Text Layers

This expression keeps two text layers visually centered relative to each other and the composition, no matter the text length or spacing. Be sure to follow the instructions in the expression comments!

Contributed by:


// Right-align the FIRST layer.
// Left-align the SECOND layer.
// Parent the second layer to the first and position it accordingly.
// Expression for the FIRST layer's position (parent layer).
// Apply this expression to the position property of the FIRST layer.
t1 = thisLayer.sourceRectAtTime();
t2 = thisComp.layer("Text 2").sourceRectAtTime();
margin = thisComp.layer("Text 2").position[0];
x = t1.width - margin - t2.width;
[thisComp.width / 2, thisComp.height / 2] + [x / 2, t1.height / 2];

Auto Align and Center Two Text Layers

Practical use case

Ideal for ensuring two text layers remain perfectly centered within the composition - especially useful for headlines and dynamic text setups where content length may vary.

Check out similar expressions

Data-driven video workflows for After Effects are easier with Plainly.

a mesh of elegant lines transparent image