4 Replies Latest reply on Jul 2, 2008 10:57 AM by (Marc_Sidon)

    Fit tables to content


      Perhaps this has been asked before, although I didn't find much on it.

      Is there a script that fits the width of a table to it's content? I need this to be done for an entire document and it would be nice if I don't have to select the table first.

      If there isn't a script like this, can someone create it?

      Kind regards,

        • 1. Re: Fit tables to content
          Loic.Aigon Adobe Community Professional
          Looking into Indesign interface, it seems that there is no way to adapt a table to its frame. By the way, I don't see any ability to set the width of a table but maybe I am wrong on this point ?
          So, is there any script that allow that, to be honest, I don't think you can get something really good.
          The closest lead I see should be something like :
          A - get the width and heigth of the frame
          B - get the number of columns and lines
          C - set the width & heigth of cells to A/B.
          You will understand how much this way can'tbe satisfying for you.
          I hope I am wrong however.
          • 2. Re: Fit tables to content
            Level 1
            Hey Loic,

            It's possible in InDesign to set the width of a cell in units. So is it possible to fit the cell size (width) to it's content?

            • 3. Re: Fit tables to content
              Level 1
              first - you need to check all cells in column for Overflow:

              Property Overflows As Boolean
              Member of InDesign.Cell
              If true, the Cell has overset text.

              and if you also need to have only one textline per paragraph in cell - you need to check number of textlines in each paragraph in cell

              Property Lines As Lines
              Member of InDesign.Paragraph
              A collection of lines.

              now - you need to increase width of column (or cell) - and check again (a) and (b)
              you need to do this as long as all cells will be not Overflowed and/or paragraphs not multiline


              • 4. Re: Fit tables to content
                I am quite into dynamic table optimization (if this is what you want to do).

                A) grow columns to a preset maximum
                B ) shrink each column until the table gets higher (or column overflows)
                (a table gets higher if a column has more lines of text)
                C) react on the situation:
                C1) if the table is bigger (in width) than the textframe,
                shrink columns again
                C2) if it is smaller, make them bigger

                If you use the right algorithms, it's quite fast as well!