Responsive center-align two text layers next to each other

Community Beginner ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

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

Views

152

Likes

Translate

Translate

Report

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

Adobe Community Professional , 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

...

Likes

Translate

Translate
Adobe Community Professional ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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
Enthusiast ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 🙂

Likes

Translate

Translate

Report

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 24, 2022 May 24, 2022

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks for welcome me

Likes

Translate

Translate

Report

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 ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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 ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

LATEST
 

Likes

Translate

Translate

Report

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