Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Responsive center-align two text layers next to each other

Community Beginner ,
May 20, 2022 May 20, 2022

Hi, I'm struggling with what I think could have an easy solution.

 

I have linked my project to a spreadsheet to enter the Artist, Featuring and Title. The featuring needs to be in the thin font style while the artist needs to be in the regular font style. Hence why I need to use two seperate layers. See example below:

OnnoSure_2-1653052056004.png

 

This is the result I'm trying to make responsive. 

 

The problem is that I want these two layers to be centered as a group. I know how to align the featuring to the artist text, but I can't seem to center the two to the comp width. When there is no featuring, the Artist name need to be centered.

 

It needs to be responsive as the input data changes with every track.

 

I hope somebody can help me 🙂

 

Kind regards,

 

 

 

 

TOPICS
Expressions
7.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 20, 2022 May 20, 2022

The most efficient way to line up text layers is to use the sourceRectAtTime() function in an expression on the position property of the first two text layers. The Anchor Point of a text layer combined with the height, top, left, and width values can be combined with the layer's position and even scale to tell you exactly where the text layer is in the comp frame and how big it is. All that is left is a little math. 

 

I. would stack all text layers on top of each other in order, with the top la

...
Translate
LEGEND ,
May 20, 2022 May 20, 2022

There's literally hundreds of tutorials on using sourceRectAtTime() to align and resize things and just typing this as a search term in your web browser will bring them up.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 20, 2022 May 20, 2022

I've already looked at a lot of these tutorials. I know how to align and size object using those expressions but can't figure out how to center two object next to each other to the entire comp size.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 20, 2022 May 20, 2022

You could probably use an expression but that could get annoying. Check this out: https://creativecow.net/forums/thread/align-two-layers-across-comp/ You can use a null layer and parent your layers to that. 

 

When testing around, I also found that just simply using different alignments in the Paragraph panel could work for you. Let me know if this helps with your problem!


~Jake
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 23, 2022 May 23, 2022

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 20, 2022 May 20, 2022

The comp is just a third value that needs to be considered, so I'm not sure what you are really having issues with. Could be as trivial as subtracting thisComp.width*0.5 somewhere.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2022 May 20, 2022

The most efficient way to line up text layers is to use the sourceRectAtTime() function in an expression on the position property of the first two text layers. The Anchor Point of a text layer combined with the height, top, left, and width values can be combined with the layer's position and even scale to tell you exactly where the text layer is in the comp frame and how big it is. All that is left is a little math. 

 

I. would stack all text layers on top of each other in order, with the top layer being the first layer, then use the layer index instead of the layer names to line up all of the layers and set the horizontal and vertical padding between words. With your design, the bottom line would be the master layer, so it would not have any expressions, and the other two layers would be offset by the bottom layer's height and centered above it by their combined width. 

 

If the first two layers are left-justified and the bottom layer is center-justified, these expressions should work:

 

// apply to the first text layer layer position property
secondTxt = thisComp.layer(index + 1);
sSize = secondTxt.sourceRectAtTime();
vPad = - 50;
p = secondTxt.position;
s = secondTxt.scale * .01;
t = sSize.top * s[1];
h = sSize.height * s[1];
w = sSize.width * s[0];
l = sSize.left * s[0];

src=thisLayer.sourceRectAtTime();
srcS = scale * .01;
srcT = src.top * srcS[1];
srcH = src.height * srcS[1];
srcW = src.width * srcS[0];
srcL = src.left * srcS[0];


x = p[0] + l + w - srcL - srcW - w  + vPad;
y = p[1] + t + h - srcT - srcH;

[x, y]


// apply to the second text layer position property
firstTxt = thisComp.layer(index - 1);
sSize = firstTxt.sourceRectAtTime();
vPad = - 50;
hPad = - 50;
p = firstTxt.position;
s = firstTxt.scale * .01;
w = sSize.width + sSize.left;
h = sSize.height + sSize.top;


srcSize = thisLayer.sourceRectAtTime();
srcScale = scale * .01;
srcWidth = srcSize.width - srcSize.left;

cntrOfst = vPad + srcWidth + w - thisComp.width;

thirdTxt = thisComp.layer(index + 1)
mstrPos = thirdTxt.position;
mScale = thirdTxt.scale * .01;
mSize = thirdTxt.sourceRectAtTime();
mt = mSize.top;


x = mstrPos[0] - (srcWidth - w) / 2;
y = mstrPos[1] + mt + vPad;

[x, y]

 

 Save those position expressions as animation presets, and you can apply them to any set of text layers. All you have to do is animate the position of the third layer in the stack.

 

I didn't take the time to fully optimize the expressions for scale, baseline shift, and paragraph justification. If I get time later, I'll do that.

 

I have also included a project file for you to fiddle examine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 23, 2022 May 23, 2022

Much appreciated, thank you so much for taking the time to help me!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 23, 2022 May 23, 2022

The only issue I still find is that the Artist text isn't centered when there is no featuring. I'm going to examine the code and fiddle around, but any help with this would be appreciated very much 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 24, 2022 May 24, 2022

I had this issue, if there is no featuring you could use a simple if then statement to ignore that position and have it center itself

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 05, 2023 Apr 05, 2023

Helps a lot. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2022 May 29, 2022

Thanks for welcome me

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 02, 2022 Jun 02, 2022

here are 2 projects. one with messy math, the other i think i managed to have a slider for your gap between the 2 texts, there is also a rcenter on the artist in case you dont use the featuring layer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 02, 2022 Jun 02, 2022
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2022 Aug 31, 2022

This was so incredibly helpful for me, thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2024 Jun 03, 2024

Quick question. How would you left alight the top layers instead of center align it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2024 Jun 03, 2024

Ahhhh! I just figured it out.

 

Center layer - changed the code from:

var w1= thisComp.layer("artist").sourceRectAtTime().width; var w2 = thisComp.layer("featuring").sourceRectAtTime().width; if(thisComp.layer("featuring").active)[(thisComp.width-(w1+w2+thisComp.layer("featuring").effect("gap")("Slider"))+306)/2+90,value[1]];else [(thisComp.width-(w1))/2+96,value[1]]

 

To :

var w1= thisComp.layer("Name").sourceRectAtTime().width; var w2 = thisComp.layer("Pronoun").sourceRectAtTime().width; if(thisComp.layer("Pronoun").active)[(thisComp.width-(w1+w2+thisComp.layer("Pronoun").effect("gap")("Slider"))+306)/2

Removed the following from the end

+90,value[1]];else [(thisComp.width-(w1))/2+96,value[1]]

Thank you all!!! This forum was great help!!!!

I just need to figure out how to create an Auto Scale Box  That would accomodate both (top line) text layers

Let me know if anyone can help. 

 

Thank you!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2024 Jun 04, 2024
LATEST

 do you mean a box that will fit around the 2 texts that will always be the width of the 2 texts ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines