6 Replies Latest reply on Apr 13, 2016 1:34 AM by fabufab

    How to center two text layers in relation to each other

    fabufab

      Hi everybody,

       

      it sounds pretty simple: I have two seperate text layers - both in the same line. One is aligned left, the other aligned right, so they spell out from the middle. As a whole I want them to be centered.

      Example.PNG

       

      But because these two texts will have different wordings in different projects I want to use the Template feature, so I can edit them in Premiere.

       

      Is there a way to tell After Effects: "Whatever text there is, take both text layers and center them as a whole." ?

       

      For the life of me I can't figure out how to get it done. The nearest I am to a solution is an expression on the anchor point of a null object, which read:

       

      w1= thisComp.layer("Text1").sourceRectAtTime().width;

      w2 = thisComp.layer("Text2").sourceRectAtTime().width;

      [(thisComp.width-(w1+w2))/2,value[1]]

       

      Then the text layers are parented to the null.

      I found it in a Creative Cow post: multiple text layers to form one. how can I center it as a whole? : Adobe After Effects Expressions

       

      The problem with this: It just works with the right-aligned text. If you edit the left-aligned text everything heads to the left.

      Does anybody have an idea how to get this to work? May there even be a simpler way than using expressions?

       

      I hope I could explain the problem clearly. If there are any details missing please let me know.

      Thank you!

       

      Regards

      Fabi

        • 1. Re: How to center two text layers in relation to each other
          Szalam Adobe Community Professional & MVP

          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?

          • 2. Re: How to center two text layers in relation to each other
            Rick Gerard Adobe Community Professional & MVP

            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:

            text.jpg

            Now use the align tool:

            align.jpg

            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.

            • 3. Re: How to center two text layers in relation to each other
              fabufab Level 1

              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...

              • 4. Re: How to center two text layers in relation to each other
                fabufab Level 1

                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?

                • 5. Re: How to center two text layers in relation to each other
                  Rick Gerard Adobe Community Professional & MVP

                  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.

                   

                  EDIT:

                  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[1]]

                   

                  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.

                  • 6. Re: How to center two text layers in relation to each other
                    fabufab Level 1

                    Wohoo, that did it! So you really can do everything with expressions. :-)

                    Thank you so much for your efforts!