Copy link to clipboard
Copied
otice in the example I gave that
When there is no table:
The bottom of the left page is aligned.
When the table is inserted, the bottom of the right page is not aligned.
In the past I would adjust the line spacing before and after the table to roughly align, but with 100 tables I'm at a loss. And the client is always changing it around, making you go crazy a few firsts.
I tried the first row baseline, but it is difficult to achieve automatic alignment because of the variable number of tables and rows per page.
Finally I tried grid layout and the bottom automatically aligns.
But another problem comes, the table is fixed in the grid, you can't move him, sometimes the table before and after spacing is not the same, it's hard to see.
You can only adjust the row height, the space before and after the table.
Do you guys have a good solution, can you share it.
Thank you very much.
For a document like this I would suggest setting the baseline grid to the same value as your body text leading and set the body text styles to align the first line to the grid.
Copy link to clipboard
Copied
For a document like this I would suggest setting the baseline grid to the same value as your body text leading and set the body text styles to align the first line to the grid.
Copy link to clipboard
Copied
Yes, there may be some headings where limiting the number of mandatory lines is better.
I'll look into it.
Thank you very much.
Copy link to clipboard
Copied
You have to make all vertical (line space/leading/cell height/table spacing) elements some value that always adds up to your total text frame height, so that no matter how you mix text and tables, they have the same total height.
Things to adjust to meet this common spacing include:
....and this will have to be continued for things like list items (bullet or numbered), headings and other content elements.
There is no simple, automated feature that can do more than help with this; it's an art and requires careful planning and meticulous adjustment of all the styles. And then you will have to accommodate variations such as 2-line table cells.
Look at it as a vertical grid, and make every element fit a vertical grid space. There's no real shortcut to that.
Copy link to clipboard
Copied
Hi @dublove, here is a script that vertically justifies each frame by adding space before and after each table. Is that what you need?
- Mark
/**
* @file Justify By Spacing Tables.js
*
* Usage:
* 1. Select some text or text frame(s).
* 2. Run script.
*
* Will attempt to add space, before and after, to each table
* so that the text frame(s) are vertically justified.
*
* @author m1b
* @version 2024-12-20
* @discussion https://community.adobe.com/t5/indesign-discussions/how-do-i-ensure-bottom-alignment-for-documents-with-tables-row-alignment/m-p/15048920
*/
function main() {
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument,
selectedTables = getTables(doc.selection);
// get textFrames
var frames = [],
already = {};
for (var i = 0; i < selectedTables.length; i++) {
var frame = selectedTables[i].parent;
if (!already[frame.id]) {
frames.push(frame);
already[frame.id] = true;
}
}
// process each text frame
for (var i = 0; i < frames.length; i++) {
var frame = frames[i],
lineCount = frame.lines.length,
tables = frame.tables,
firstSpace = tables[0].spaceBefore,
space = 0;
// calculate the excess space
while (frame.lines.length === lineCount)
tables[0].spaceBefore += 3;
while (frame.lines.length !== lineCount)
tables[0].spaceBefore -= 0.5;
// measure space
space = tables[0].spaceBefore - firstSpace;
// reset
tables[0].spaceBefore = firstSpace;
// space out tables evenly
var spacingAmount = space / (tables.length * 2);
for (var j = 0; j < tables.length; j++) {
tables[j].spaceBefore += spacingAmount;
tables[j].spaceAfter += spacingAmount;
}
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Justify By Spacing Tables');
/**
* Get tables from `items`.
* @author m1b
* @version 2024-12-20
*
* Finds tables inside different objects,
* eg. selection, page, text frame, story.
* Supply a filter function to narrow down
* the table(s) even more.
*
* @param {Document|Page|PageItem|TextFrame|Cell|Text} items - item, collection or array to get tables from
* @param {Boolean} [onlyFirst] - only return the first table found
* @param {Function} [filter] - only match tables that pass this filter function
* @param {Array[Table]} [found] - results (private argument for recursive calls)
* @returns {Array[Table]} - the found table(s) * if onlyFirst flag then can be {Table}
*/
function getTables(items, onlyFirst, filter, found) {
// sanity
if (items == undefined)
return [];
if (found == undefined)
found = [];
else if (
onlyFirst
&& found.constructor.name == 'Table'
)
// immediately return the table
return found;
if (!items.hasOwnProperty('0'))
// put in array to process
items = [items];
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.constructor.name == 'Table') {
if (
filter == undefined
|| filter(item) === true
) {
// item is a table
if (onlyFirst)
return item;
else
found.push(item);
}
}
else if (item.constructor.name == 'TextFrame') {
var textFrameTables = item.tables.everyItem().getElements();
if (
item.hasOwnProperty('textFrames')
&& item.textFrames.length > 0
)
// check in anchored text frames
textFrameTables = textFrameTables.concat(getTables(item.textFrames, onlyFirst, filter));
found = found.concat(textFrameTables);
}
else if (
item.hasOwnProperty('tables')
&& item.tables.length > 0
)
// item contains tables
found = found.concat(getTables(item.tables, onlyFirst, filter));
else if (
item.hasOwnProperty('parent')
&& item.parent.constructor.name == 'Cell'
)
// parent is a table cell
found = found.concat(getTables(item.parent.parent, onlyFirst, filter));
else if (
item.hasOwnProperty('paragraphs')
&& item.paragraphs.length > 0
&& item.paragraphs[0] !== item
)
// is in a story, which may contain tables
found = found.concat(getTables(item.paragraphs, onlyFirst, filter));
else if (
item.hasOwnProperty('parentTextFrames')
&& item.parentTextFrames.length > 0
)
// is in a story, which may contain tables
found = found.concat(getTables(item.parentTextFrames, onlyFirst, filter));
else if (
item.hasOwnProperty('parentStory')
)
// is in a story, which may contain tables
found = found.concat(getTables(item.parentStory, onlyFirst, filter));
else if (
item.hasOwnProperty('pageItems')
&& item.pageItems.length > 0
)
// contains page items, which may be tables
found = found.concat(getTables(item.pageItems, onlyFirst, filter));
else if (
item.hasOwnProperty('parent')
&& item.parent.constructor.name != 'Document'
&& item.parent.constructor.name != 'Spread'
)
// has a parent which might be a table
found = found.concat(getTables(item.parent, onlyFirst, filter));
}
return found;
};
Copy link to clipboard
Copied
Thank you very much.
That's pretty awesome that you can use a script for that.
The function of this script seems to be similar to the text box “Align ends”?
Maybe James Gifford-NitroPress is right, there is no shortcut.
Help me out with this one sometime, it should be very useful. Use the same script to control alignable images and textboxes to specific boundaries.
Copy link to clipboard
Copied
By your comment, I will assume that I misunderstood what you needed.
I had a look at the other thread—and one linked from that one—but to be honest, you haven't specified your needs well enough for me to be bothered helping with that. The key is always to do as much work as possible yourself to make it easy for people to help you.
It is common when helping someone with scripting that you write a script that solves the problem, and then the OP says yes but my document has <some extra whatever> and it needs to handle that, too. So the first script is, perhaps, useless and needs to be re-written totally, or maybe no script is possible and my time is wasted.
So when I see a request that is impossible to understand, I shrug and move on. Sorry.
- Mark
Copy link to clipboard
Copied
I am sorry.
I feel guilty.
The language is different and I have trouble expressing myself.
I have updated the problem description and provided sample files.
Thank you very much.
Copy link to clipboard
Copied
@dublove You do not need to feel guilty. I know for you it is a struggle with the language, and it is great that you make the effort. I assume your native language has no effective translation service, which makes it so much more difficult. Please do not be discouraged.
I just want you to explain your questions better because scripters will prefer to help when they can understand your problem quickly and confidently. You have updated your other question and you have done a very good job, so I know you definitely understand what I meant. Thank you.
- Mark
Copy link to clipboard
Copied
This is a great example of why I sigh a bit when someone jumps in with a script to fix something, especially from somewhat loose examples and requests. Don't misunderstand — although I'm not a script guy myself (which is a little odd; ID is just about the only venue in which I don't do low-level coding and so forth!) I appreciate the many standard scripts out there and the willingness of the script types to jump in. And the sheer power scripts can bring to complex projects.
But.
Unless they are massive and "error trapped" to the walls, and fully tested on a variety of documents, scripts tend to solve one (1) problem under either ideal or narrow conditions. Sometimes that's all that's needed — run script, some manuscript-wide glitch vanishes or a complicated change is made. But when it comes to more general problems, mostly to do with optimal formatting under workaday conditions... all too often, it takes too many rounds of adjusting the script, or accepting that what it does is closer to hack than fix, to get to a useful result.
Often, all that effort seems greater, sometimes, than just using skill and ID's tools to fix the issue.
And in this case, where a whole book needs to be formatted according to a single rule (even bottom alignment) simply hacking at table heights isn't really a good solution. There may be some automation, tool, helper (like selective use of Vertical Justification, or text-fitting by slightly tweaking top/bottom spacing on one table on the occasional page) or technique that makes it easier than my hard-road summary above... but learning to do that meticulous style and page adjustment to get page alignment as an organic result, rather than being sloppy and applying a quick band-aid fix (which will likely cause cascading problems that then need to be fixed in turn)... I'd suggest that effort put into honing a skill is better spent than effort spent building a one-shot, fixed-result patch.
Especially when the scope of the project is not fully understood and a quick tweak of table spacing might not be the right approach at all.
There's also a gap between those who can compose a script on the fly, from exceptional skill, and those who are somewhere lower on that knowledge ladder. I'm not sure it's useful for "Einstein to do your math homework for you," as it were — it sure won't lead to the user learning much of use for the next, or slightly variant problem.
Scripting is a wonderful asset, no question. But I feel like too many reach for it like a hack or band-aid, too quickly, sometimes.
Copy link to clipboard
Copied
It's all about life.
Perhaps.
I've kind of contributed to the forum.
Copy link to clipboard
Copied
@dublove, your posts are interesting and often present intriguing and worthwhile questions to investigate. I think most of us are aware you're participating through translation as well, and try to keep our answers straightforward and "translation compatible."
None of what I said above applies to you. I thought it was a good place to point out that a quick, custom script is not always the right answer to a formatting problem, no matter how easy it is to create for an experienced scripting user. They are often too rigid, too narrowly focused and subject to failure on small overlooked document aspects. There are often shorter processes to turn to over several rounds of creating and refining a script to do it in a few seconds.
I'm not in any way discouraging script use or these quick, very-well-intended posts providing them. Just suggesting they're not always a good first-round option when seeking a solution.
Copy link to clipboard
Copied
Hi @James Gifford—NitroPress, your sigh of disapproval is understandable, and you make many cogent arguments which I appreciate.
Unfortunately, scripting for me is a pleasure, akin to doing a crossword... or perhaps building a crossword might be more apt. I am pleased with the script I wrote here—it was fast to write, fairly elegant at a quick glance and, as a side effect, caused me to improve a function I haved used frequently (getTables, last updated over 18 months ago).
The fact that it didn't solve the OP's specific issue is definitely a black mark in terms of diluting the thread, but I think it is good to be free to explore different approaches to a question on a site like this—even unlikely ones, such as my script here, and in this case no harm is done to the historical record because the proper answer is marked correct, quite rightly.
On your point about Einstein doing your math homework: yes, sometimes it is like this on a basic level. But my perspective is different. I write my scripts so that people like me will see them and learn scripting, exactly the way I learned: from people like me posting their scripts, and to whom I am grateful. If sometimes I am doing someone's math homework, I am also leaving behind a little puzzle to be picked up and studied by someone an AI in the future, which is what I care about more.
My grumbling to dublove was not annoyance, but was intended to urge them to more fully specify and explain their needs. Again, my pleasure is in the making, much more than the giving. I have a fairly long, sporadic, history of helping dublove and they have a number of questions they want me to answer still but, so far, alas, I am not inspired. "It's all about life" says dublove—yes indeed!
Anyway, thanks for your comment; I always appreciate your contribution. We are actually remarkably on the same page here, except for me being unrepentant—which I hope doesn't lead to bad feelings, because I have none.
- Mark
Copy link to clipboard
Copied
Hey, don't take anything I've said as a diss on scripts, scripting or especially those of you who whip out the custom ones on the fly.
I just — in summary — think they're sometimes too quickly offered as a solution, when the whole request and project isn't necessarily understood, and unless the OP is script-literate themselves, even simple issues can take several rounds to correct... all to get to a fix that might have been better/faster served without the detour.
We all have areas of expertise that make these very advanced approaches simple and obvious... to us. But I, for example, would never just throw out a CSS statement as a fix, not without being sure the OP understood the what/how/implementation... and even then I'd probably give a complete CSS snippet for context.
Just consider the audience, and how even a simple script can go wrong if some aspect of the project is misunderstood, broken or omitted. S'all I got to say. 🙂
Copy link to clipboard
Copied
Don't worry, technology is going to proliferate?
It's good that technology is moving fast.
Copy link to clipboard
Copied
Hey @James Gifford—NitroPress, a quick last thing on the topic of "jumping in with a script"... I should have mentioned that I literally *only* see posts where "scripting" is tagged. So, there's that. But anyway, see you next time I jump in. 🙂
- Mark
Copy link to clipboard
Copied
Uh, no. I rarely pay any attention to scripting discussions or comment on scripting solutions offered. (There are, for example, several current scripting topics I haven't even looked at, because they don't otherwise cross my radar.) But if you think I overstep in being a devil's advocate for simple, organic approaches when a script seems like complicated overkill, I can dial it back. I'm certainly not out to discourage any well-intentioned questions, solutions or help.
Perhaps it's that you only notice my comments in the scripting-tagged discussions you follow. 🙂 Been in any, say, EPUB or QR code chats lately?
I will add that some rising curve of script topics begin with "ChatGPT didn't get this right no matter how hard I tried, so..." which to me is not really a positive trend. There's a flavor there of telesurgery systems making anyone think they can do brain surgery, and I'd think the brain surgeons have better ways to spend their time than straightening out AI's fumbling efforts at expertise.
Copy link to clipboard
Copied
Perhaps the fact that you've wasted some time
Some people will also have more anxious thoughts because of you.
In fact, I sincerely hope that Adobe will see some of the general problems and focus on solving the foundational ones.
I wouldn't normally expect a complex problem to be solved.
But if it's a basic, general technical problem, a quick script is very much desired.
Maybe Adobe has lost its way with ChatGpt or “Smart Typography”.
Copy link to clipboard
Copied
Hi @m1b
This script of yours is the equivalent of aligning the ends.
My other posting, the bottom of the table aligns to the TYPE AREA to make more sense, you can definitely get creative with that.