Skip to main content
Known Participant
February 1, 2024
Answered

Automated tab position in table figures....

  • February 1, 2024
  • 3 replies
  • 1565 views

I am working with hundreds of account tables. In the figures, I keep -2 point (right) decimal tab  [ ) ] to keep digits  align. But time to time, table sizes change and therefore I have to change this tab position manually. Is that any automated way to handle this? Any GREP formate or style condition? If so, it will save lot of my time. I greatly appreciate your advice...... Thank you.  

This topic has been closed for replies.
Correct answer danaken3

And one another thing danaken3, 

Some header rows conain bottom line with years and LKR '000. This part also need to adjust with the figures. Do you have any idea about how to do that? If this script can't do that, any new script for run again? No matter to use two mouse clicks per table....... I am happy enough..... 

 


Ah I see -- try this one:

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    /*Searches for all instances of "Table_Figures" paragraph style. 
    (Paragraph style must be saved within the "Table_Styles" folder.)
    For each result, finds width of parent cell. Overrides the first 
    (existing) tab stop position to: cell width minus 2mm. 
    Deletes all other tab stops.*/
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Table_Styles").paragraphStyles.item("Table_Figures");
    var myResults = app.findGrep();
    var myCell;
    var origViewMeasurements = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    for (i=0; i<myResults.length; i++) {
        try {
            if (myResults[i].tabStops.length > 1) {
                for (j=myResults[i].tabStops.length-1; j>0; j--) {
                    myResults[i].tabStops[j].remove();
                }
        }
            myCell = myResults[i].parent;
            myResults[i].tabStops[0].position = myCell.width - 2;
        }
        catch(err) {
        }
    }

    /*Searches for all instances of "Table_Header" paragraph style. 
    (Paragraph style must be saved within the "Table_Styles" folder.)
    For each result, finds width of parent cell. Overrides the first 
    (existing) tab stop position to: cell width minus 2mm. 
    Deletes all other tab stops.*/
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Table_Styles").paragraphStyles.item("Table_Header");
    myResults = app.findGrep();
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    for (i=0; i<myResults.length; i++) {
        try {
            if (myResults[i].tabStops.length > 1) {
                for (j=myResults[i].tabStops.length-1; j>0; j--) {
                    myResults[i].tabStops[j].remove();
                }
        }
            myCell = myResults[i].parent;
            myResults[i].tabStops[0].position = myCell.width - 2;
        }
        catch(err) {
        }
    }    

    app.findGrepPreferences = NothingEnum.nothing;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = origViewMeasurements;

    alert("Script complete");

}

3 replies

Barb Binder
Community Expert
Community Expert
February 2, 2024

Hi @nalink10768017:

 

Outside of @TᴀW's script, there isn't an easy answer. This is why a lot of folks give up on decimal alignment, and just center the numbers. It's not the right way to do it, but it's quicker. Personally, I'd go with the script!

 

~Barb

~Barb at Rocky Mountain Training
TᴀW
Legend
February 2, 2024

It sounds like this (not free) script of mine might help: https://www.id-extras.com/products/centertablecolumns/

danaken3
Participating Frequently
February 1, 2024

Can you create a few different paragraph styles, one for each column width, and define the tab settings within each style? Or am I misunderstanding your request?

Known Participant
February 2, 2024

Thanks for your promt reply. 

But this is not I mean. My tables has different size columns. When I change fist column text, other columns needs to resize. Then this tab position change. Example:

Column width - 30 points

Decimal tab position - 28 points. 

When I change this column width to 40 points, still this decimal tab stay in 28 point. I need it goes to 38 point. Always minus 2 points with the column width. I want to do it automated, because working with hundreds of tables. I think GREP command built in cell style can solve this issue.  Or any other way. 

danaken3
Participating Frequently
February 2, 2024

danaken3, 

See attached ID file. I keep one tab  and run the script. After that, new and old - two tabs are there. 


To clarify -- the most recent script I posted contains solutions to both of your latest requests (adjusting the tab stops for the Table-Header style, and removing any extra tab stops). If you run that, it should properly adjust the tab stops for both the Table_Figures and the Table_Header paragraph styles. It should also remove any extra tab stops. When I run the script on that file, it works for me. 

 

Are you using the latest script or one of my previous scripts I posted?