Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Align to decimal point and center

Guest
Jan 29, 2018 Jan 29, 2018

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?

5.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 30, 2018 Jan 30, 2018

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

    })

...
Translate
Community Expert ,
Jan 29, 2018 Jan 29, 2018

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:

Screenshot 2018-01-29 13.32.35.png

Use figure spaces in front of the short lines with Type > Insert White Space > Figure Space:

Screenshot 2018-01-29 13.33.05.png

Now when you resize the column, the figures stay centered.

Screenshot 2018-01-29 13.33.52.png

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2018 Jan 30, 2018

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2018 Jan 30, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2018 Jan 30, 2018

BarbBinder​, vinny38​, the script does its job.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2018 Jan 30, 2018

Wow! That's great news! May I mark Vinny's answer as correct, piotreba​? (Or you can.)

(vinny38 —now I need something similar for FrameMaker! )

~Barb

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 30, 2018 Jan 30, 2018

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??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2018 Jan 30, 2018
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 29, 2018 Jan 29, 2018

Hi,

Just by curiosity, could you post a screenshot?

Best,

Greg, from FRIdNGE

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2018 Jan 30, 2018

Greg, I'm not sure whether your request refers to my original post or the response by Barb.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 30, 2018 Jan 30, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2018 Jan 30, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 30, 2018 Jan 30, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 30, 2018 Jan 30, 2018

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 30, 2018 Jan 30, 2018

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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines