Copy link to clipboard
Copied
Hi,
I am trying to set up a paragraph style which I want to use in a table for aligning figures to a decimal dot. However, as table columns width varies, I wouldn't like to set a fixed X, but rather I would like the X to adjust depending on the column width, always to be more or less centered (so the wider the column is, the X is greater). Is there any way to accomplish that?
Hi
Can you give this script a try and report back?
(run it on a copy of your document first)
...if (app.documents.length > 0) {
var myDocument = app.documents[0];
//----------------------------Open Dialog box----------------------------//
var myStylesNames = [];
for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
myStylesNames.push(myDocument.allParagraphStyles.name);
}
var myDialog = app.dialogs.add({
name: "Align to dots script",
canCancel: true
})
Copy link to clipboard
Copied
Hi piotreba ,
Not within the InDesign feature set. You can add a decimal tab stop to a table cell (without having to add a tab character, by the way) but the the tab stop is fixed distance from the left edge of the column. If you change the column width, you'll need to update the tab location. Maybe ask in the InDesign Scripting forum?
There's a workaround that is useful in limited situations—not too many instances, and you need to use font with monospaced figures.
Set the figures to align center with the column:
Use figure spaces in front of the short lines with Type > Insert White Space > Figure Space:
Now when you resize the column, the figures stay centered.
As I said, good to know but of limited usefulness. I deal with this situation more often than I'd like to. Sometimes using figures spaces is the answer, sometimes moving the tabs is the answer, but my preference is hold off on the alignment until we reach the end of edits. My editors can proof the numbers in advance, but they wait on proofing the alignment until I let them know that I've finalized it.
~Barb
Copy link to clipboard
Copied
Thanks BarbBinder,
Indeed in my case playing with figure spaces would be challenging. But it's a good hint anyway for some situations.
So I' have related question though: can I configure paragraph style in a way so that I set some basic tab options and then I manually adjust, here, aligning to a decimal, but without producing style overrides?
Copy link to clipboard
Copied
Hi piotreba ,
can I configure paragraph style in a way so that I set some basic tab options and then I manually adjust, here, aligning to a decimal, but without producing style overrides?
That's the definition of an override: you set up a style with a dec tab position and then tweak it for the various column widths.
You could save multiply styles for the column widths, but that's also too much work.
Let us know if Vinny's script helps.
~Barb
Copy link to clipboard
Copied
BarbBinder, vinny38, the script does its job.
Thanks
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for reporting back. Glad it helped.
as Greg pointed it out, no need for the "add a tab before (if doesn't exist)" part. You can remove lines 36 to 52. It will make the script a bit faster.
Just like Greg's script, you'll have to run it again if you move columns width or insets.
Barb... FrameWhat??
Copy link to clipboard
Copied
LOL. I do layout in (and teach) both.
I just discovered that you don’t need to add a tab for a decimal tab (decimal can be any character) in a cell yesterday. When I was keystroking my first answer to this thread, I took them out to move onto the figure space part and was surprised that the text didn’t move. It’s one of the many benefits of helping out on this forum. I often think I learn as much as those who come here looking for help.
~Barb
Copy link to clipboard
Copied
Hi,
Just by curiosity, could you post a screenshot?
Best,
Greg, from FRIdNGE
Copy link to clipboard
Copied
Greg, I'm not sure whether your request refers to my original post or the response by Barb.
Copy link to clipboard
Copied
Hi,
It's about your original post! Could you post a sample of what you mean?
or do you talk about tables with numbers columns? [as Barbara showed us!]
Best,
Greg, from FRIdNGE
Copy link to clipboard
Copied
Yes, Greg. as I wrote in my post I meant columns in a table. I used “more or less centered” to refer to the decimal dot rather than the whole number.
Best
Copy link to clipboard
Copied
For sample:
Dropbox - 0286_DecimalTabStopsOnSelectedTable_FRIdNGE.jsxbin
Just select a dot in a table and run the script! [totally workable for free script]
No tab. It includes a global undo! If you change the width of columns after having running the script, launch it again!
A more global version could play all the tables of a doc, a story, a election of text including tables or just one table.
Best,
Greg, from FRIdNGE
Copy link to clipboard
Copied
Interesting.
Didn't know a character-aligned tabstop didn't require a tab to work in a cell
(so lines 36 to 52 of my script are just useless)
Pity you didn't provide the jsx, but well...
Copy link to clipboard
Copied
Hi
Can you give this script a try and report back?
(run it on a copy of your document first)
if (app.documents.length > 0) {
var myDocument = app.documents[0];
//----------------------------Open Dialog box----------------------------//
var myStylesNames = [];
for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
myStylesNames.push(myDocument.allParagraphStyles.name);
}
var myDialog = app.dialogs.add({
name: "Align to dots script",
canCancel: true
});
with(myDialog.dialogColumns.add()) {
staticTexts.add({
staticLabel: "Choose the paragraph style applied to the cells you want to align on dot"
});
}
with(myDialog.dialogColumns.add()) {
var myDDSTyles = dropdowns.add({
stringList: myStylesNames,
selectedIndex: 0
});
}
var myResult = myDialog.show();
if (myResult == true) {
var myParaStyle = myStylesNames[myDDSTyles.selectedIndex];
}
myDialog.destroy();
//---------------------------- add a tab before (if doesn't exist) ----------------------------//
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.properties = {
findWhat: "^(\\d)",
appliedParagraphStyle: myParaStyle,
}
app.changeGrepPreferences.changeTo = "\\t$1";
app.activeDocument.changeGrep();
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
//---------------------------- create array ----------------------------//
var myText = [];
var allText = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();
for (i = 0; i < allText.length; i++) {
if (allText.appliedParagraphStyle.name == myParaStyle) {
myText.push(allText);
}
}
//---------------------------- Set tab alignment and apply to cells ----------------------------//
var tabStopProperties = {
alignment: TabStopAlignment.CHARACTER_ALIGN,
alignmentCharacter: "."
};
for (var i = 0; i < myText.length; i++) {
var cellWidth = myText.parent.width;
var cellLeftInset = myText.parent.leftInset;
var cellRightInset = myText.parent.rightInset;
var position = (cellWidth - cellRightInset - cellLeftInset - 1.058) / 2;
myText.tabStops.everyItem().remove();
myText.tabStops.add();
myText.tabStops[0].properties = tabStopProperties;
myText.tabStops[0].position = position;
}
} else {
alert("Please open a document");
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now