• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

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

New Here ,
Sep 29, 2009 Sep 29, 2009

Copy link to clipboard

Copied

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

TOPICS
How to

Views

59.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2018 Feb 17, 2018

Copy link to clipboard

Copied

Hi Obi-wan Kenobi​. Is there an up-to-date link to your script?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 18, 2019 Aug 18, 2019

Copy link to clipboard

Copied

Obi-wan Kenobi​ ce script existe-il encore dans tes archives?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

Hi,

Can we use same for cs6 also. If yes so please send me the link for same.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

May I please get a link for the auto-fit table options - sorry I was late for the party  :))))  thanks!   ðŸ™‚

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

We used to be able to do this with a Quadex 5000 Typesetter way back in the 1980s... tabs (for tabular work, or as we call them today, tables) were based on the longest line in each column, with specified left/right column margins. I would think that in 2017, the programmers we have today should "at least" be able to duplicate this functionality.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Unless you personally add your request for that feature, the product managers will never know. There are literally requests for thousands of different "must have" features in the queue. It's a little like an election: Make your vote count.

Feature Requests/Bug Reports

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

What works for me is:

  1. Select the cells
  2. Go to Table > Cell Options > Text...
  3. Choose Rows and Columns
  4. Set Row Height to "At Least" then fill in a height that is smaller than the minimum height you know you need.

Then the rows will adjust to fit your content.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

columns, not rows.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2021 Nov 07, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

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":

rudiwarttmann_0-1637160012626.png

rudiwarttmann_1-1637160060800.png

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

 

uwe@die-3-richters Laubender: I really try to shorten the time for contributions 🙂 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

Rudi Warttmann said:

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

 

Hi Rudi,

don't hold back!

 

Cheers,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

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

 

https://github.com/gsingelmann/indd_autocolumn 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 24, 2022 Apr 24, 2022

Copy link to clipboard

Copied

simple things long discussions

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Hi @rehana36276218 ,

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

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024

Copy link to clipboard

Copied

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 )

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2024 Oct 19, 2024

Copy link to clipboard

Copied

LATEST

Well, then go ahead ... what is your question to the community ... ?
You will quickly recognize that just counting the number of characters by far won't do the job - even if you use a even-spaced font like "Courier". Eg: What if there is more than one line of text in a cell? You will have to make quite a few decisions along the way and need to first make sure that certain preconditions are met. 
That said, you could certainly mimic the Excel function mentioned in this thread, letting the user select any cell in the column in question and then start a script. The script would have to examine line by line of text in any cell of this column, find out the largest one and take this as the basis of the new column width. So far it's pretty straightforward, the only noteworthy thing is that the actual width of a line can be calculated as the difference of the horizontal position of the first and the last insertion point. 
Now you should have everything at hand to write a great script that mimics Excel "Adjust Column Width" function, and of course you would share it here with the community 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines