AutoFit Columns

AutoFit Columns User Guide


The purpose of AutoFit Columns is to automate the process of determining the narrowest possible width of a table column that will accommodate all the data in the column, without the data becoming overset or wrapping to multiple lines. Autofit considers cell insets, paragraph indents, column strokes, and merged cells in its calculation.


AutoFit columns consists of a single AutoFitColumns.jsx file. A good tutorial on how to copy this into the correct folder on your computer can be found at

Running the script for the first time

After installing the script, display InDesign’s Scripts panel on the screen (Window > Utilities > Scripts), select one or more table columns and double-click on the AutoFitColumns.jsx script in the Scripts panel.

If you click About, and then select Create menu item, the next time that you quit and then start up InDesign, you’ll see an Id-Extras menu added to your menu bar. You can then choose AutoFit Columns from this menu to run the script if you wish.

Using the script

You don’t need to select an entire column before running the script. If you just place your text cursor in a single table cell, the column that contains that cell will be autofit when you run the script. If you select a range of cells, the columns containing those cells will be autofit.

AutoFit Dialog Box

When you run the script, the dialog below appears. This dialog box is “sticky” and will remain on the screen until you click the Close button. If you have enough room on your screen, you can just leave it on the screen, much like a panel, and continue working on your layout. That way the Autofit button is just a single click away.

AutoFit dialog box

When you click the Autofit button, the width of the selected column(s) in your table are adjusted to the minimum value that will accommodate the longest line of text in each cell without wrapping to a second line.

financial table before and after running AutoFit

A financial table before (left) and after (right) running AutoFit Columns on all four columns.


Effects of the “Preserve Existing Line Breaks” Option

If you don’t select the Preserve Existing Line Breaks option, any wrapping text in columns will be “unwrapped” into a single row. If you select this option, the wrap will be maintained. If a line break or paragraph return has been typed into a cell, this break will always be honored, and never overridden.

A table showing the effects of the Preserve Existing Line Breaks option

The original table (left), all columns AutoFit without Preserve Existing Line Breaks selected (center) and with Preserve Existing Line Breaks selected (right)


Table Width Adjustments Feature

The other option in the AutoFit dialog box is the Table Width Adjustments feature. When this is selected, AutoFit will do a secondary adjustment to the table after the selected column(s) have been adjusted to the minimum width. It widens (or narrows) each column proportionally to make the table fit the current table width, the table’s frame, a portion of the frame, or a specific number of text columns. It can be helpful to understand the method by which this is done.

When the column widths must be increased to fit the table, frame, etc., the width of every column, including the selected columns that were just autofit will be increased proportionally to fit the target.

When the column widths must be decreased to fit the table, frame, etc., the width of every column except the selected columns that were just autofit will be decreased proportionally to fit the target.


Every operation of the script is completely undo-able. Because of the “non-modal” nature of the dialog box that is necessary to make the box “sticky” on the screen, you will usually need to click away from the dialog box before the undo keyboard shortcut will function properly.

Known Limitations

The script doesn’t honor breaks in Rotated column heads, and the “width” of these rotated heads isn’t always calculated correctly by the script.

If you are using a decimal tab stop to align numerals on their decimal point within a column, the tab stop is ignored.


Article Comments

  1. Raphaël Freeman

    March 22, 2023 10:36 am Reply

    This is insanely fast but unfortunately does not work with Optical Margin Alignment switched on. Since I always use optical margin alignment, it would be useful to update the script accordingly!

    • Ariel

      March 23, 2023 2:47 am Reply

      Hi Raphael,
      Thanks for pointing this out. I’ve release version 1.0.4 which should now work with optical margin alignment switched on in table stories as well. (As well as some bugs with paragraph justification issues.)

Leave a Comment