Answered
m1bCorrect answer
Community Expert
Oct 17, 2025 2:24 PM UTC
Hi @dublove try this:
/**
* @file Get Column Width of Table.js
*
* Example showing how to get a table from the selection,
* and then the parent text frame's column width.
*
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/how-to-determine-the-number-of-columns-in-a-text-box-and-obtain-the-width-of-one-column/m-p/15550852
*/
function main() {
var doc = app.activeDocument;
var table = getParent(doc.selection[0], 'Table');
if (!table)
return alert('Please put cursor into a table and try again.');
var textFrame = table.storyOffset.parentTextFrames[0];
var columnCount = textFrame.textFramePreferences.textColumnCount;
var columnGutter = textFrame.textFramePreferences.textColumnGutter;
var b = textFrame.geometricBounds;
var frameWidth = b[3] - b[1];
var inset = textFrame.textFramePreferences.insetSpacing;
var columnWidth = (frameWidth - inset[1] - inset[3] - (columnGutter * (columnCount - 1))) / columnCount;
alert('Column width = ' + columnWidth);
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Get Column Width of Table');
/**
* Return an item with the matching constructor name, if a parent of `item`.
* @author m1b
* @version 2025-10-18
* @param {PageItem|*} item - an Indesign DOM item.
* @param {String} constructorName - the constructor name to match.
* @returns {*?}
*/
function getParent(item, constructorName) {
try {
while (item.hasOwnProperty('parent')) {
if (constructorName === item.constructor.name)
return item;
item = item.parent;
}
} catch (error) { }
};
