Skip to main content
Participant
September 29, 2009
質問

Is there a way to "autofit" an InDesign table's columns to fit their content?

  • September 29, 2009
  • 返信数 17.
  • 68468 ビュー

Am I being dense about this? I've looked through all the help documentation, searched online in various forums, blogs, etc...I can't find anything about being able to autofit a table's column to fit its content.

This type of thing is a piece of cake in Excel...just double-click the border between the cells and it'll autofit.

But, in InDesign (as far as I can tell), it's an entirely manual process involving zooming in and manually adjusting the borders between cells until the red table cell overflow circle goes away.

Not fun when you have a half dozen tables on a single page...and then eight additional pages with similar numbers of tables.

Is there any solution to doing this? A script? A plugin? The next version (whenever it comes out)? Something else?

Thanks in advance for any help,

Doug Thompson

Manager of Web and Electronic Communications

Ohio Wesleyan University

返信数 17

Participant
January 21, 2025

I don't know if anyone still needs this, but I wored out how to do it when I was trying to find out how to do it.

Select the cells you want to adjust, then go to the table settings in your top menu bar. Set it to 'At Least' then set the size bigger than you need it. Then use the arrows to reduce the table size down until they are all the minimum size they can be with thier contents. 

Participating Frequently
January 21, 2025

Doug is struggling with the automatic horizontal, not vertical adjustment of a table cell based on its content. Which is _not_ part of InDesign's functions (for obvious reasons).

TᴀW
Legend
January 26, 2025

My Autofit Columns script (not free) snaps the column width to the cell content. It takes account of cell and table strokes, and works with rotated tables, etc. Plus, after fitting the columns, it optionally lets you readjust the entire table width proportionally to fit the width of the text frame or column, or a simple fraction of those widths.

Worth checking out: https://www.id-extras.com/products/autofit-columns/

Participant
October 19, 2024

We want to create a JavaScript function that scans each cell in a given table, calculates the width of the text within each cell based on the number of characters, and then assigns that width to the cell.

Community Expert
October 19, 2024

Hi @Imaginative_Charm5E91 ,

well, the width of the cell is determined by the width of its table column.

So if you change the width of the cell you'll change the width of all cells of its column at the same time.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

 

jacquiford
Participant
July 21, 2023
rehana36276218
Known Participant
April 25, 2022

simple things long discussions

Community Expert
September 13, 2022

Hi @rehana36276218 ,

depending on the contents of the cells this is not a simple thing at all.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Doe Johns
Inspiring
February 1, 2022

Auto Column script by Gerald Singelmann will make it for you. Just select the "All Auto On" button.

 

https://github.com/gsingelmann/indd_autocolumn 

Participant
September 13, 2022

Thanks a lot, looked for long to manage that. Just incredible this fonctionality has never implented...

 

Community Expert
September 13, 2022

Hi @PIerrest ,

I think, @Doe Johns did not understand the difference between the initial task of our OP @dethompsowu and Gerald Singelmann's script. Quoting Gerald:

 

"One idea of the script is not change the overall width of the table. To achieve that you can set some columns to "auto". After adding up all non-auto-values the remainig table width is automatically distributed over the auto-values."

 

The contents of a table cell will be not calculated in any form. The amount of white space the contents creates does not matter to Gerald's script. "Optimized width" of a column or "optimized height" of a table is a totally different thing.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Community Expert
November 17, 2021

Rudi Warttmann said:

"Laubender: I really try to shorten the time for contributions"

 

Hi Rudi,

don't hold back!

 

Cheers,
Uwe Laubender

( ACP )

Participating Frequently
November 17, 2021

There is in fact no "straightforward" mechanism in InDesign. Trying to shrink the cells using "if ... cell.overflows" will make you end up banging your head against the wall because InDesign would need a recompose after each step, well, plus ideally an "idle" phase to reliably redraw the table.

My solution, based on the idea of my friend Martin Fischer, goes like this: I assess the largest cell entry in each column and then assign this value, plus an addition for rounding errors, to the column. Something like:

// Spaltenbreitenoptimierung
// --------------------------------------------

/*
	V 1.0 vom 17.11.2021
	Voraussetzung: Einfügemarke muss in der Tabelle blinken.
*/

// ------------------------------------------------------------------------------------
// Variablen, gerne zu bearbeiten
	var zugabe = 0.2  	// Zugabe in Millimetern
// ------------------------------------------------------------------------------------

//	Variablen, intern
	var col, c = null;
	var textwidth, cwidth = 0;
	var t = null;

// Auswahl?
	if ( app.selection.length == 0 || app.selection[0].parent.parent.constructor.name != "Table") {
		alert ( "Bitte Einfügemarke in Tabelle stellen", "Keine Tabelle" );
		exit();
	}

// Tabelle ansprechen
	var t = app.selection[0].parent.parent;

// Spalten von rechts nach links durchgehen
	for ( var j = t.columns.length - 1; j >= 0 ; j-- ) {

		col = t.columns[j];

		// durch alle Zeilen durchgehen und die Textbreite feststellen
			for ( var i = 0; i < col.cells.length; i++ ) {
				c = col.cells[i];
				textwidth = c.texts.firstItem().insertionPoints.lastItem().horizontalOffset - c.texts.firstItem().insertionPoints.firstItem().horizontalOffset;
				cwidth = Math.max(cwidth, textwidth);
			}

		// der Spalte die ermittelte Maximalbreite zuweisen und um die Zugabe erhöhen	
			col.width = cwidth + zugabe;

		// und wieder auf Null
			cwidth = 0;
	}

alert ( "Fertig!", "Fertig!" );

where the cursor needs to blink somewhere in the table.

However, this solution shall only show the idea; you have to consider left/right cell insets, multiple rows in a cell, and so on.

Interestingly, this solution is quite performant; this table is optimised in "no time":

Hope this helps and gives you a kind of starting point.

 

@7707890 Laubender: I really try to shorten the time for contributions 🙂 

Inspiring
November 17, 2021
does this work with English version of Indesign 2022 - tried but kicks out
error message that I can't read.
[image: cloudHQ] Powered by
cloudHQ
Participating Frequently
November 17, 2021

I'm afraid I can't see you image - are you sure that the cursor is blinking in any cell when starting the script? 

Participant
November 7, 2021

Set row height to 'at least' and type in a really low height like 2mm, it autofits

Community Expert
May 4, 2021

I did not say, that I have that old script available…

 

Regards,
Uwe Laubender

( ACP )

Community Expert
May 4, 2021

pensacola2013 said: "May I please get a link for the auto-fit table options - sorry I was late for the party :)))) thanks!"

 

Please note, that this thread started in September 2009. The said script is ( maybe ) from around 2015, also some years ago when tables were missing some features like graphic cells or footnotes for example. I would not expect it to run error free on any table done with InDesign 2021.

 

Regards,
Uwe Laubender

( ACP )

Inspiring
May 4, 2021

ok, thank you so very much - need this feature!!!!!   :))))))))))