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

Challenge – Hanging Bracket in Table Cell Script?

Community Beginner ,
Jan 22, 2010 Jan 22, 2010

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

TOPICS
Scripting
5.7K
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 22, 2010 Jan 22, 2010
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 Beginner ,
Jan 22, 2010 Jan 22, 2010

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?

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 22, 2010 Jan 22, 2010

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

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 Beginner ,
Jan 22, 2010 Jan 22, 2010

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.

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 22, 2010 Jan 22, 2010

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

          }

     }

}

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 Beginner ,
Jan 22, 2010 Jan 22, 2010

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

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 22, 2010 Jan 22, 2010

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;

          }

     }

}

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
Advocate ,
Jan 31, 2010 Jan 31, 2010

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

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 Beginner ,
Aug 05, 2016 Aug 05, 2016

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

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 Beginner ,
Sep 05, 2024 Sep 05, 2024

still waiting...lol

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 ,
Sep 05, 2024 Sep 05, 2024
LATEST

Hmm! A little patience! …. 😉

 

(^/)  The Jedi

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