Center Align an Object or Text into Another Object or Shape Layer
Copy link to clipboard
Copied
Hi, How can I center align an object or a text into another object in After effects? For exmaple I need to center align the texts in the attached picture inside the respective yellow boxes. How can I do that?
Copy link to clipboard
Copied
Alignment for text layers is controlled by how you create it - just like in any other Adobe program. Similarly, alignment options will appear in the top tool bar with multiple layers selected as in other Adobe programs as well. Anything more fancy than that can be achieved by adjusting anchor points and positions, using scripts and expressions, but without any info about what teh project needs to do and how adaptable it needs to be there seems little point in confusing you by pointing to these things. It would probably be a good idea to start by actually reading the online help on some basics.
Mylenium
Copy link to clipboard
Copied
Hello Mylenium, My question is pretty simple. How can I center align the text (14, 30, 60) in the attached picture into the Yellow boxes, as 14 in the first, 30 in the second & 60 in the last?
Copy link to clipboard
Copied
As per my first reply - select the text and box, use the alignment options in the horizontal toolbar.
Mylenium
Copy link to clipboard
Copied
In this case, make sure your text is center-aligned in the Paragraph panel, then align it to the box.
You could do this using the Align panel (set "Align Layers to:" to Selection).
You could also simply make sure the X Position values match (assuming the box Anchor Points are also centered).
If you need these to stay centered within the boxes as they move around, you'll need to parent the text to the box, or vice-versa.
Copy link to clipboard
Copied
Shape layers and Text layers have the ability to read the left edge and top edge of the object as well as the width and height. You can use sourceRectAtTime() to center a text layer below a shape or a shape layer under a Text layer. Here's the expression for centering a shape layer over a text layer, no matter how the paragraph justification or baseline shift has been set.
L = thisComp.layer(index - 1);
S = L.sourceRectAtTime();
W = S.width/2 + S.left;
H = S.height/2 + S.top;
x = L.position[0] + W;
y = L.position[1] + H;
[x, y]
If you want the Text layer to be centered above a layer with the Anchor Point in the center of the layer, then apply this expression to the Text layer's position;
T = thisLayer.sourceRectAtTime();
xC = T.width/2 - T.left;
yC = T.height + T.top /2;
L = thisComp.layer(index + 1);
[xC - T.width, yC] + L.position
If you are dealing with Shape layers for the background, you can also incorporate sourceRectAtTime to adjust the size of the shape layer.
One of those expressions will solve your problem if the text layer is just above the layer you want to act as the background.
Copy link to clipboard
Copied
I'm kinda late, but the way i do that is i just select both the shape and the text, and align them to center of the comp, then i just free move them to where i want to move the box with the text inside!

