5 Replies Latest reply on Apr 13, 2017 9:50 AM by Laubender

    Creating vertical gradients in table rows

    steveb2

      Is it possible to create vertical gradients across each row in a table? I know this has been discussed on and off here but I can't find any good answers.

       

      This code almost works . . . it assumes that there is text in the first cell of each row, and calculates the page coordinates of the cell (and hence the row) from the baseline:

       

      var defineRowGradient = function ( theRow ) {

           var firstCharacter = theRow.cells[ 0 ].characters[ 0 ];

           var minimumOffset = theRow.minimumFirstBaselineOffset;

           var topInset = theRow.topInset;

           var top = firstCharacter.baseline - ( minimumOffset + topInset );

           var left = firstCharacter.horizontalOffset - theRow.leftInset;

           theRow.gradientFillStart = [ left, top ];

           theRow.gradientFillAngle = -90;

           theRow.gradientFillLength = theRow.height;

      }

       

      By "almost works" I mean that it works fine on tables that fit in a single frame. It falls apart when the table flows to another frame or another page. The page coordinate calculations seem to hold up, but the gradient isn't applied correctly to each row. The vertical position creeps up or down, or the rows are filled with solid color or left blank. It doesn't seem to matter if the gradient is applied as part of the cell style, or as an override. It seems as if something needs to be reset each time the table jumps to a new frame.

       

      What's missing? Is there a way to fix this so it will work with multi-frame tables?

        • 1. Re: Creating vertical gradients in table rows
          Laubender Adobe Community Professional & MVP

          Hi Steve,

          what is your version of InDesign?

           

          Also consider that row height could change after the gradient is applied.
          E.g. text is edited. I think, every time something is done to the table, the gradient must be applied anew.

           

          Could you share a screenshot where you see the problem with a table that is running through different text frames?
          Maybe this problem also occurs, if the table flows through different columns of one single text frame?

           

          Regards,
          Uwe

          • 2. Re: Creating vertical gradients in table rows
            Laubender Adobe Community Professional & MVP

            See the following screenshot.

             

            The first table is just one I added to the frame without doing anything in regards of row height.
            A default table where I added "a" to the first cell of the second row.

             

            I assume that you expect a result like the one at the bottom.

             

            LinearGradientAppliedToTableRow.png

             

            I think, there is more to consider than only tables that flow with more than one text frame.

             

            FWIW: Without a character in the cell your function is not working.
            Consider the baseline value of the first insertion point of a cell to start out calculating anything.

             

            Regards,
            Uwe

            • 3. Re: Creating vertical gradients in table rows
              steveb2 Level 1

              Thanks for the replies. I'm using the latest version of InDesign CC. Please see my original post regarding the need for text in the first cell of each row. The script does require that in order to calculate the page position of the row. And you are right about the need to reapply the script after the table is edited. This may limit its usefulness. But in my case the tables only extend a few pages, and the work required to reapply (and tweak) the gradients would be manageable.

               

              Here is the script applied to a two-page table:

               

              gradientSpread.png

               

              Left page: Perfect! Right page: Not so much. The first row is OK but then the gradient drifts upward until it disappears. I have checked the numbers calculated by the script, and the gradient start positions and lengths are correct.

               

              And you are right about multiple-column tables. Here is a two-column table on a single page. Similar result:

               

              gradientSingle.png

              • 4. Re: Creating vertical gradients in table rows
                steveb2 Level 1

                Also meant to say thanks for the tip re: using the first insertion point instead of first character. I will look into that.

                 

                Steve

                • 5. Re: Creating vertical gradients in table rows
                  Laubender Adobe Community Professional & MVP

                  Hi Steve,
                  I can confirm your problems with table rows running in a second column or in a second text frame.

                  And there are odd things going on, if you change the height of the text frame and allow more or less cells flow in one column of the text frame.

                   

                  Regards,
                  Uwe