If the text is animating out from the center, the source should probably be centered. It might look rather odd otherwise.
But, if you really want to do it...
Precompose the two text layers.
Use your sourceRectAtTime().width and divide it by two on the x of the anchor point of the precomp. Does that work?
Most folks start a text layer by selecting the type tool and clicking somewhere in the frame. This doesn't help when you are trying to line things up by the numbers later.
Here's how I would handle your problem. First I would select the paragraph panel and select right justified and then start a new text layer with the timeline selected by mashing down on all of the keys on the right side of the keyboard + t (ctrl/cmnd + alt/option + shift + t) and then start typing your first line of text, then press return, then select left justified in the paragraph panel and type the second line. Then I would select the second line and adjust the baseline in the Character panel until both paragraphs line up. Then I would set the Align Panel to Composition and click the center tool. That's it. It would look like this:
Now use the align tool:
If the baselines are properly set everything will be perfect.
Then all you have to do is add two text animators and make your adjustments. Use one animator for the first paragraph and the other for the second. EZ PZ.
First of all, thank you for your quick answer. This is a very neat way, for setting Text up once in AE.
But I want to be able to edit the text in Premiere Pro, without needing to go back to AE to adjust the alignement. Besides there will be an animation on top for which I need two seperate text layers.
Right now I think there just may be no simple way to achieve my goal...
First of all thank you for your quick answer. Unfortunately that won't work.
Maybe I don't understand your approach correctly, but if I precomp the text layers the precomp gets a new fixed width that is not dependent on the text layers. It's not possible to center them with a precomp because the precomp thinks of itself as centered. Do you know what I mean? And did I misunderstand you?
There is no pre-comp involved in the technique. The alignment tools will not work with a pre-comp. In the top screenshot notice the selected text and the baseline setting in the Character Panel. I've just adjusted the baseline in the second paragraph of text to move it up so that it lines up with the baseline in the first paragraph of text.
Unfortunately the process becomes a bit more difficult if you want to be able to use this comp as a dynamically linked editable text asset in Premiere Pro. Centering becomes a problem. It's pretty easy to get the width of the text layer but the anchor point is based on the paragraph and I don't know of any way to take the width of the first paragraph of text and add it to the width of the second paragraph of text and adjust the anchor point to be in the center of the combined paragraphs.
You could go back to the idea of two text layers but use the combined width of each layer and the ratio between the widths to control the position of a null. If you then parented both layers to the null centering the null with an expression based on the width of both layers and the ratio between the width of the left and right text would do the trick. I'd have to think about how to write that expression for a bit. That is probably the solution to your problem but I don't think I could write that expression in my head.
What you would want to do is calculate the total width of both layers (tw) and then calculate the ratio of the width's of both layers (rw / lw) and then multiply the width of the left layer by the ratio so you could calculate the offset. You might have to calculate the ratio of the left layer to the total width of both layers. Like I said I will have to think about that for a minute. There's also the problem of the space between the two layers. You'll need to add a space before the first letter of the Right text layer but the size of the right layer will not take into account the space so you will have to measure that and add it in to keep things perfectly centered.
So I did some more thinking and I was making this way too difficult. All you have to do is calculate the difference between the width of the two text layers and divide that by 2 and add it to the comp center. Name your text layers Right Text and Left Text and add this expression to a null.
r = thisComp.layer("Right Text").sourceRectAtTime(time,false);
rt = r.width;
l = thisComp.layer("Left Text").sourceRectAtTime(time,false);
lt = l.width;
cc = thisComp.width/2;
dif = (lt - rt) /2;
[dif + cc, value]
Now hold down the shift key and parent both lines of text to the null. If you don't want to use the null trick you can add the expression to both text layers. Using the null makes things easier to move around. The expression could also be modified to allow you to position the null or the layers anywhere you want in the comp.
Wohoo, that did it! So you really can do everything with expressions. :-)
Thank you so much for your efforts!