A workaround for text alignment in After Effects templates, two ways
Normally you align text with the paragraph panel when you’re working with text in After Effects. But this proves a problem for template-builders: After Effects doesn’t allow you to keyframe text alignment via the paragraph panel. That means if you’ve got a control effecting your text (like a dropdown menu or checkbox), you’re not going to be able to control alignment the way you would position or any other keyframable thing.
There are a couple of ways to get around this problem when you’re building an essential graphics template; the simplest involves using the anchor point. And if you have a single line of text this generally works. However when you try to add multiple lines of text in the essential graphics panel, you run right back into the alignment issue again.
Before we get into a workaround for the multi-line problem, I’d like to show you how I use the anchor point to keyframe alignment in my essential graphics templates. Here’s my tutorial, if you learn better reading step by step, just scroll past the video to find written instructions.
Keyframe alignment using the anchor point.
In order to lock our text into position, we need to place the anchor point either at the beginning, middle or end of the text line, and we want to be able to toggle through this placement in the essential graphics panel. To do this we’re going to use our good friend sourceRectAtTime.
SourceRectAtTime allows us to define the corners of our text by giving us the height, width, top and left corners. To get the bottom, right or center we just have to do some simple math. To place the anchor point in the bottom-left position of our text layer we’d use this expression:
a = thisComp.layer("Text").sourceRectAtTime(); height = a.height; width = a.width;top = a.top; left = a.left; x = left; y = top + height; [x,y];
For the bottom-right position we’d use this expression:
a = thisComp.layer("Text").sourceRectAtTime(); height = a.height; width = a.width; top = a.top; left = a.left; x = left + width; y = top + height; [x,y];
And for the center position we’d use this expression:
a = thisComp.layer("Text").sourceRectAtTime(); height = a.height; width = a.width; top = a.top; left = a.left; x = left + width / 2; y = top + height; [x,y];
Now that we have these basic expressions down, we can build a larger expression using an if/else if statement that will allow a user to toggle through each of these options via a dropdown menu in the essential graphics panel. To do this, create a control layer (here called “CTRL”) where the dropdown menu (here called “ALIGNMENT”) lives. Change the dropdown menu’s properties so that option 1 is left, option 2 is center and option 3 is right. Then the following expression can be placed in the target text layer’s anchor point:
a = thisLayer.sourceRectAtTime(); height = a.height; width = a.width; top = a.top; left = a.left; if ( thisComp.layer("CTRL").effect("ALIGNMENT")("Menu")==1 ) { x = left; y = top + height; } else if (thisComp.layer("CTRL").effect("ALIGNMENT")("Menu")==2 ) { x = left + width/2; y = top + height; } else { x = left + width; y = top + height; } [x,y]
Keyframe alignment using source text
But what if we want to have multiple lines of text here, like a descriptive paragraph or a multi-line title? My solution involves nesting the text in a precomp which is then time-remapped. It seems complicated, and truthfully it is a complicated solution for something that, in theory, has a fairly simple fix (just let us keyframe alignment already, Adobe!). But because I often work with lower third names and titles, I find this method makes it very easy to stick other layers of text to the top or bottom and have them change y-position should more lines be added.
Create a composition. Create a text layer and pre-compose it. Let’s call this first layer “GUIDE TEXT.” In the precomp, create another text layer and call it “ALIGNED TEXT.” Twirl down Text > Source Text and pickwhip the source text of ALIGNED TEXT to the source text of GUIDE TEXT.
Select your ALIGNED TEXT layer. In the Paragraph panel, left-align your text. In the ALIGNED TEXT layer, create a source text keyframe at 1 second. Scrub to 2 seconds, center-align your text and create a new keyframe. Scrub to 3 seconds, right-align your text and create a new keyframe.
In the essential graphics panel, make sure you have your original comp selected. Drag the Source Text of GUIDE LAYER into the essential graphics panel. This is where you will enter and change your text.
Back in the original comp, create a null layer that you will use as a control layer. Let’s call this CTRL. Add a dropdown menu effect control to this layer, Effect > Effect Controls > Dropdown Menu Control. Let’s call this effect control ALIGN. Pull this effect control to your essential graphics panel and rename the options Left, Center and Right.
Select your precomp and enable time remapping, Layer > Time > Enable Time Remapping. Remove the ending keyframe. Option+click the stopwatch to enable expressions on the Time Remap, and enter this if/else statement:
if(thisComp.layer("CTRL").effect("ALIGN")("Menu")==2){ 2.5; } else if(thisComp.layer("CTRL").effect("ALIGN")("Menu")==3){ 3.5; } else{ 1; }
What this expression is doing is returning a specific time on this precomp depending on what option is selected in your dropdown menu. Because we have keyframed the source text at seconds 1, 2 and 3 in the precomp, it’s returning these different iterations of our source text. You could use this method to switch between fonts or other text styles should you need to. But here’s a bonus tip: A simpler way of swapping between font choices would be to use setFont with a checkbox effector (using a ternary operator in this example for brevity).
a = text.sourceText.style.setFont("FONT CHOICE 1"); b = text.sourceText.style.setFont("FONT CHOICE 2"); (thisComp.layer("CTRL").effect("FONT")("Menu")==1)?a : b;
Happy coding!