is now part of CreativePro.com!

Adding Shading to Alternate Paragraphs With GREP Find/Change

10

Tables offer the possibility to apply shading to alternate rows. But when it isn’t possible or desirable to convert a list of paragraphs to a table just to apply alternate shading, the shading can be applied by a simple GREP query.

. . . .

This article is for members only. To continue reading, please sign in, or sign up for a membership today. Thanks for supporting CreativePro!

BECOME A MEMBER

CreativePro membership keeps you up-to-date with the technology, solutions, and resources to strengthen your professional development.

For just $6.50/month (billed annually), you’ll get access to valuable benefits, including:

  • 12 monthly issues of CreativePro Magazine, filled with practical, real-world tutorials written by experts
  • Downloadable resources including templates, fonts, scripts, design assets, cheat sheets, and more
  • Hundreds of members-only tutorial and tip articles
  • Top Tips for InDesign, Photoshop, and Illustrator ebook collection
  • Discounts on events and books
  • and more...

Sign up now!


Peter Kahrel is the author of several eBooks on InDesign and scripting, including GREP in InDesign, published by CreativePro Network. He also wrote the feature article on "Getting a Grip on GREP" in InDesign Magazine Issue 59.
  • C says:

    You may also set the ‘next paragraph style’ option in those styles. Then select some text in the first paragraph and right-click the first style in the paragraph styles panel, and choose ‘apply and then next’.

  • Peter Kahrel says:

    C — That’s true. (Hadn’t thought of that; I never use ‘Next style’, didn’t develop the habit.) Set Shaded’s next style to ‘No Shade’ and No Shade’s next style to Shaded, and you can use the ‘Apply and then next’ method.

    Shading still won’t update correctly automatically though, so after changes in the story you’d still have to re-select the text and ‘apply and then next again’.

    The grep approach is a bit more convenient, I think. Especially because you can put it in a very simple script, which in turn can be assigned to a keyboard shortcut. First save the query (using the disk icon at the top of the Find/Change window); call it e.g. ‘alternate-shading’. Then this two-line script runs the query:

    app.loadFindChangeQuery (‘alternate-shading’, SearchModes.GREP_SEARCH);
    app.activeDocument.changeGrep();

    Peter

  • Pu says:

    Would this work you include this grep within the paragraph style?

  • Chris says:

    Alternative solution for some applications – a single-column table with no borders, one row per paragraph, with alternate rows shaded

  • Chris says:

    And adding to my comment above, only just noticed Peter mentioned that as a solution in the very first paragraph. Apologies.

  • Peter Kahrel says:

    > Would this work you include this grep within the paragraph style?

    No, it wouldn’t: the scope of a GREP style is a single paragraph, and the used expression goes beyond the single paragraph.

  • Nick says:

    Nice one. When I created and installed the script, however, I had to use double quotes, not single ones, for this to work.

  • Peter Kahrel says:

    That’s odd, it should work with both double and single quotes. Maybe when you copied-and-pasted the text the quotes became curly quotes, and in a script all quotes must be straight. But you got it to work anyway.

    As an addition, the two-line script as shown above targets the whole document. If you want to target a selection of text, change the second line as follows:

    app.selection[0].changeGrep();

    And if you want to target a story, select one of the story’s text frames and change the second line to this one:

    app.selection[0].parentStory.changeGrep();

    P.

    • Nick Cuccia says:

      Thanks. I copied your code from the screen to Sublime Text with what I thought where straight quotes and saved as jsx file. Kept getting error, so I checked other scripts on my Mac and noticed one used double quotes. I (novice here) figured that was the problem. Sometimes retyping the same character can make all the difference in things. Meanwhile, this has inspired me to dip into GREP and I was up watching Michael Murphy’s Lynda.com videos on it (the tutorials there all seemed to go back a ways, CS4). Thanks for the inspiration!

  • T.E. says:

    Great tutorial!

  • >