12 Replies Latest reply on Nov 1, 2013 5:37 AM by Andreas Jansson

    Reg. Decimal Alignment in selected column of a Table

    Sathya Rani M

      Hi All,

       

      Can anyone help me to align the selected column cells of table in decimal?

       

      Thank you in advance.

       

      Regards,

      Sathya Rani M

        • 1. Re: Reg. Decimal Alignment in selected column of a Table
          TᴀW Adobe Community Professional & MVP

          Select your column. Open the Tabs panel. Add a decimal tab where you

          want it and that's it. All the numbers will line up. In a table, you do

          not even need to add the actual tab mark before the numbers.

           

          Ariel

          • 2. Re: Reg. Decimal Alignment in selected column of a Table
            Sathya Rani M Level 1

            Thank you for replying. I need to achive this via indesign javascript. please advice.

             

            ~Sathya Rani M

            • 3. Re: Reg. Decimal Alignment in selected column of a Table
              Jump_Over Level 5

              Hi,

               

              As Ariel wrote, in case of table you don't need to type "tabs" inside cells to reach a goal.

              Below is an example of last column's setting

               

              var 
                   mCols = app.activeDocument.textFrames[0].tables[0].columns[-1],
                   mTarget = mCols.cells.everyItem().texts.everyItem().getElements(),
                   len = mTarget.length;
              while (len-->0)
                        mTarget[len].tabStops.add({
                                  alignment: TabStopAlignment.CHARACTER_ALIGN,
                                  alignmentCharacter: ".",
                                  position: mCols.width - 10
                                  });
              

               

              Notice: it should work in a simple doc as an example (1 textFrame and 1 table)

               

              Jarek

              • 4. Re: Reg. Decimal Alignment in selected column of a Table
                TᴀW Adobe Community Professional & MVP

                Thanks Jarek for taking care of this. I thought I was in the regular

                forum when I answered...

                • 5. Re: Reg. Decimal Alignment in selected column of a Table
                  Sathya Rani M Level 1

                  Thank you for replying.

                   

                  from the provided code, the table cells are not reflecting with dot align.

                   

                  My exact case is "I need to align selected column cells with dot alignment" .

                  Please help me.

                   

                  Kindly excuse if anything found wrong.

                   

                  ~Sathya Rani M

                  • 6. Re: Reg. Decimal Alignment in selected column of a Table
                    Jump_Over Level 5

                    Hi,

                     

                    If your goal is exact case you need to provide exact source doc or edit applied code according to your local circumstances.

                     

                    Provided code is an example to illustrate how it works - not a solution for exact case. It should work if run with a new doc - 1 text frame - 1 table inside.

                     

                    alignmentCharacter: "."     ==> here you can type an alignment char

                     

                    Jarek

                    • 7. Re: Reg. Decimal Alignment in selected column of a Table
                      Andreas Jansson Level 2

                      Jarek's script works fine for me. A very good demonstration. You just need to create a test doument and add a single table to it. (It will not work on any given document.) This forum is a place to share and learn, and to get tips on how to make scripts. Often you will not get complete solutions.

                       

                      Here is an alternate suggestion: you could create a paragraph style with the tabs set as Jarek describes.

                       

                      Define the alignment character on the tabs tab of the paragraph style dialogue. Then, in your script, just assign that paragraph style to the selection of your document.

                       

                      There is another thing that is relevant to add: you need to have the the cell contents LEFT aligned. Any other alignment will ruin the "Align to decimal" setting!

                       

                      On the image below, the text is RIGHT aligned. That is why my text is not paying attention to the Align to decimal setting (that is also assigned).

                      Capture.PNG

                      • 8. Re: Reg. Decimal Alignment in selected column of a Table
                        Sathya Rani M Level 1

                        I have a document with one textframe and one table has in it and selected the entire column.

                         

                         

                        Now I need to align all the selected to dot align. I have tried with the below code snippet. but not getting the output.

                         

                        Please help me out in this.

                         

                        var

                             //mCols = app.activeDocument.textFrames[0].tables[0].columns[-1],

                             mCols = app.selection[0],

                             mTarget = mCols.cells.everyItem().texts.everyItem().getElements(),

                             len = mTarget.length;

                             alert(len);

                        //while (len-->0)

                        for(var i=0; i<len; i++)

                        {

                                  mTarget[i].tabStops.add({

                                            alignment: TabStopAlignment.CHARACTER_ALIGN,

                                            alignmentCharacter: ".",

                                            position: mCols.width - 10

                                            });

                                        }

                         

                         

                        ~Sathya Rani M

                        • 9. Re: Reg. Decimal Alignment in selected column of a Table
                          TᴀW Adobe Community Professional & MVP

                          Why actually do you need a script for this? InDesign aligns numbers on

                          the decimal point very nicely without a script. Just create a paragraph

                          style with the appropriate tab settings and apply as needed to your

                          tables...

                          • 10. Re: Reg. Decimal Alignment in selected column of a Table
                            Sathya Rani M Level 1

                            Thank you for all. At last i found the output as jarek suggested.

                             

                            Thanks for all once again for spending time on this.

                             

                            code:

                            var

                                 mCols = app.selection[0],

                                 mTarget = mCols.cells.everyItem().texts.everyItem().getElements(),

                                 len = mTarget.length;

                            for(var i=0; i<len; i++)

                            {

                                      mTarget[i].tabStops.add({

                                                alignment: TabStopAlignment.CHARACTER_ALIGN,

                                                alignmentCharacter: ".",

                                                position: mCols.width - 40 // Just adjusted the value

                                                });

                                            }

                            • 11. Re: Reg. Decimal Alignment in selected column of a Table
                              Laubender Adobe Community Professional & MVP

                              @Andreas – And not to forget:

                              use the right font (OTF) with the right feature for the alignment of digits:

                               

                              Table_TabAlignDecimal.png

                              The same table,  the same  OTF formatting; with two different fonts.

                              Left column: Contextual (OTF)
                              Right column: Tabular Lining (OTF)

                               

                              Of course, you could chose otherwise, if you prefer a stronger reading order from left to right.

                               

                              Uwe