Skip to main content
Known Participant
February 1, 2024
Answered

Automated tab position in table figures....

  • February 1, 2024
  • 3 replies
  • 1568 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

This is a very rudimentary script but maybe it could work for you. See the notes I included below -- I made a few assumptions but let me know if those aren't true. When you place your cursor in a cell and run the script, it will go through each cell in that column and replace the existing tab stop with a new one. Note it's not creating any new paragraph styles, so these are just overrides we're making, which will make it difficult to readjust en masse later. But if you were going to do manual updates anyway, maybe this could save you some time.

Are you familiar with how to save and run scripts? 

//Place cursor in the column to be updated (do not highlight a whole cell or column).
//Then run the script.
//Assumes there is only one paragraph in each cell.
//Assumes there is already a tab set up for the paragraphs.
//Will not adjust tabs in top (header) cell.
app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

var myColumn = app.selection[0].parent.parentColumn;
var myCells = myColumn.cells;
var myParagraph;
var myTabStop;

var myDecimalPosition = myColumn.width - 2; 
//Replace number 2 above with the desired inset from right. 
//Uses measurement units as defined in the document (e.g., pts, picas).

    for (i=1; i<myCells.length; i++) {
        myParagraph = myCells[i].paragraphs[0];
        myTabStop = myParagraph.tabStops[0];
        myTabStop.alignment = TabStopAlignment.CHARACTER_ALIGN;
        myTabStop.position = myDecimalPosition;
    }

}