9 Replies Latest reply on Aug 5, 2016 7:18 AM by michaelr17246981

    Challenge – Hanging Bracket in Table Cell Script?

    dasilvaj

      I don't know anything about scripting but....

       

      Can a script be written to handle hanging brackets in financial tables: where financial numbers are right aligned and any negative number brackets extend out to the right. Optical Margin Adjustment doesn't work. Have handled it with a cell style with a smaller inset but there must be a better way...

        • 2. Re: Challenge – Hanging Bracket in Table Cell Script?
          dasilvaj Level 1

          Hi Rob

           

          I've been doing financial tables that way for many years but am now having to utlize the Table + Cell Features of InDesign and I haven'tt found an efficient way of handling the hanging brackets.

           

          Maybe I'm missing something?

          • 3. Re: Challenge – Hanging Bracket in Table Cell Script?
            [Jongware] Most Valuable Participant

            It's a tab setting inside the table's cells. Select the entire column and call up the Tab bar. Then add an Align to Decimal tab:

             

            hangbracket.PNG

            • 4. Re: Challenge – Hanging Bracket in Table Cell Script?
              dasilvaj Level 1

              Had forgotten you could put tabs in a table cell. I'd use an align to bracket. There are also $ signs at top/bottom of tables. A tab would do that but it's not as flexible if column widths vary....

               

              I use insets, right indent tabs and a column to the right but am wondering if there is a better approach?

               

              I format large numbers of tables so hope to use a quick, flexible method (different column widths). How you would approach it if you had 100+ tables to do, regularly, under tight deadlines? I've attached a sample.

              • 5. Re: Challenge – Hanging Bracket in Table Cell Script?
                [Jongware] Most Valuable Participant

                Well, I would write a script. Or ask for one ... oh, you did ask

                You are correct, decimal tabs work great if all of your columns are the same width, but for different column widths it might be easier to add an invisible ")" to the numbers that don't end with one. With the text aligned to the right, it'll be as perfect as you can get.

                 

                This quickie works only on selected cells in a table. It inserts the invisible ")" after each first line in each of the selected cells that are right-aligned -- I think that's the safest way, as the occasional regular text should not be right-aligned.

                 

                Theoretically, it's possible to automate it even further, going over all of your hundreds of tables; but I'm sure it should not add the parenthesis to every cell in every table. It's best to keep a modicum of user control; in this case, you have to manually select the rows (or cells) with only numbers before running the script.

                 

                 

                for (cell=0; cell<app.selection[0].cells.length; cell++)
                {
                     myCell = app.selection[0].cells[cell];
                     if (myCell.paragraphs.length > 0 && myCell.paragraphs[0].justification == Justification.RIGHT_ALIGN)
                     {
                          text = myCell.paragraphs[0].contents;
                          if (text.substr(text.length-1) != ")")
                          {
                               myCell.paragraphs[0].insertionPoints.item(-2).fillColor = app.activeDocument.swatches[0]; // [None]
                               myCell.paragraphs[0].insertionPoints.item(-2).contents = ")";
                          }
                     }
                }
                 
                

                • 6. Re: Challenge – Hanging Bracket in Table Cell Script?
                  dasilvaj Level 1

                  Thanks so much for the script but I can't really modify the data, it often has to be exported back to the client. I think it would have to be more about adjusting the inset/formatting of the cells containing  brackets. It may be just a pipedream. I keep hoping that InDesign has something that I have been overlooking....

                  • 7. Re: Challenge – Hanging Bracket in Table Cell Script?
                    [Jongware] Most Valuable Participant

                    Changing the right inset of each cell is also possible, but the script needs to know the width of a parenthesis. This one inserts one temporary, measures it, then does a sneaky "undo" to remove it again. Next, the width is added to the current right offset.

                    Other than the previous script, you should not run this more than once per table!

                     

                     

                    for (cell=0; cell<app.selection[0].cells.length; cell++)
                    {
                         myCell = app.selection[0].cells[cell];
                         if (myCell.paragraphs.length > 0 && myCell.paragraphs[0].justification == Justification.RIGHT_ALIGN)
                         {
                              text = myCell.paragraphs[0].contents;
                              if (text.substr(text.length-1) != ")")
                              {
                                   x = myCell.paragraphs[0].insertionPoints.item(0).horizontalOffset;
                                   myCell.paragraphs[0].insertionPoints.item(0).contents = ")";
                                   x -= myCell.paragraphs[0].insertionPoints.item(0).horizontalOffset;
                                   app.activeDocument.undo();
                                   myCell.rightInset += x;
                              }
                         }
                    }
                     
                    

                    • 8. Re: Challenge – Hanging Bracket in Table Cell Script?
                      jay fresno Level 1

                      I don't know anything about scripting either, and maybe I'm not fully understanding the question -- but why not use Jongware's idea of a decimal aligned tab? You don't need to have a decimal in the numbers; you just need table columns that are a consistent width. I tried it on a table similar to yours and it seems to work fine.

                       

                      Untitled-2.gif

                      • 9. Re: Challenge – Hanging Bracket in Table Cell Script?
                        michaelr17246981

                        Is there a way to have the figures aligned to brackets and have them consistent when set in any width column?