Skip to main content
Participant
July 27, 2023
Question

Equal Spacing for Multiple Editable Text Layers in a Template

  • July 27, 2023
  • 3 replies
  • 847 views

I'm creating some motion graphic templates for a client with some fairly specific requirements, and this one has me stumped.

 

I have 9 text layers that need to be editable as part of the template but also retain their equal spacing between, and their central position to the canvas.

 

I've tried numerous approaches with sourceRectAtTime(); but can't seem to get it to work for the full 9 boxes.

 

Any help would be greatly appreciated at this point!

This topic has been closed for replies.

3 replies

Mathias Moehl
Community Expert
Community Expert
July 29, 2023

Pins & Boxes is very helpful for these kinds of layouts.

 

To keep the spacing between different texts, use pins & parenting.

If text A should stay at the right side of text B, for example, create a pin for the right side of B and parent A to it. Then A moves with the pin when B changes its size.

 

And here is a tutorial showing how to center entire layouts using Pins & Boxes:

 

The great thing about this centering approach is that it can center any conent, no matter how complex it is.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Community Expert
July 27, 2023

By far, the easiest solution would be to draw a text box that is centered in the composition and then select Justify Center as the paragraph style.  

 

If you want nine layers, the math gets a little complicated. Every layer needs to get the width of each text layer, add them up, subtract the width from the total width of the line, and then dive that value by 8. The first text layer (left justified to make it easier) would have the X position set to the left edge of the line of words; then, each succeeding layer would be offset in x by the width of the layer and the spacing calculation.

 

If you have nine text layers at the top of the timeline and you wanted the total width of the nine layers to be 80% of the comp width the position expression for the top layer would look like this:

c = thisComp.width/2;
tw = thisComp.width * .8 / 2;
x = c - tw;
[x, value[1]]

The position expression for all the other layers would look like this:

w1 = thisComp.layer(1).sourceRectAtTime().width;
w2 = thisComp.layer(2).sourceRectAtTime().width;
w3 = thisComp.layer(3).sourceRectAtTime().width;
w4 = thisComp.layer(4).sourceRectAtTime().width;
w5 = thisComp.layer(5).sourceRectAtTime().width;
w6 = thisComp.layer(6).sourceRectAtTime().width;
w7 = thisComp.layer(7).sourceRectAtTime().width;
w8 = thisComp.layer(8).sourceRectAtTime().width;
w9 = thisComp.layer(9).sourceRectAtTime().width;

tWidth = w1 + w2 + w2 + w4 + w5 + w6 + w7 + w8 + w9;
trgtWidth = thisComp.width * .8;
sp = trgtWidth - tWidth;
refL = thisComp.layer(index - 1);
x = refL.sourceRectAtTime().width + refL.position[0];
c = thisComp.width/2;


[x + sp/9, refL.position[1]]

Putting the text layers at the top of the timeline makes the expressions a lot simpler because you can use the layer index to keep things lined up.

 

I hope this helps.

Community Expert
July 27, 2023

Dan's solution involves a lot less typing.

Dan Ebberts
Community Expert
Community Expert
July 27, 2023

Assuming your text layers are consecutive layers in your layer stack, a position expression like this (applied to each text layer) should work:

firstIndex = 1;
lastIndex = 9;
gap = 20;

totalWidth = (lastIndex - firstIndex)*gap;
leftAmt = 0;
for (i = firstIndex; i <= lastIndex; i++){
  r = thisComp.layer(i).sourceRectAtTime(time,false);
  totalWidth += r.width;
  if (i < index){
    leftAmt += r.width + gap;
  }
}

myLeftEdge = (thisComp.width - totalWidth)/2 + leftAmt;
r = sourceRectAtTime(time,false);
myUL = toComp([r.left,r.top]);
myOffset = myUL[0] - myLeftEdge;
value - [myOffset,0]

Set the values for the first three variables to match your setup (index of first text layer, index of last text layer, gap between layers).

 

Participant
July 31, 2023

This was great Dan thank you! But I still got a bit of overlapping unfortunately – Decided to go with the plugin to save the headache at this point.

Dan Ebberts
Community Expert
Community Expert
August 1, 2023

Hmmm... I suppose that could happen if the text layers have been scaled. The expression could defend against that, but I didn't include that feature.