is now part of CreativePro.com!

Changing the Color of Headings Based on Section

8

Some books have different-colored headings to indicate different sections. But if you have 5 sections, with 5 colors, do you need 5 different paragraph styles? There’s nothing wrong with that, but here’s another method you might consider.

What if you added a “1” at the beginning of each heading that needed to be in section 1, a “2” before the second section’s headings, and so on. For example:

Sectionhead1

Then what if those numbers could trigger InDesign to color the style differently? and make the number go away automatically so that it looked like this:

Sectionhead3

Cool? So what fiendish feature allows this kind of transformation? Why, grep styles of course! (Is there anything that our superhero friend can’t do?) :)

In this case, I made three character styles: one that set the text red, one that sets it green, and one — my favorite — makes the text disappear (defined as .1 pt tall, 1% horizontal scale, and a color of None). Then I applied it all with these grep styles:

grep styles to apply color

Nothing too fancy here. The first two styles look for the number 1 or 2 at the beginning of the paragraph (and apply the appropriate style to the entire paragraph; the last style looks for any number at the beginning of a paragraph.

Now, I know that there are plenty of complaints coming as to why this isn’t a good idea, including:

  • Never apply a character style to a whole paragraph: To which I reply, “feh? there is always an exception.”
  • You’ll see the numbers when you export to epub or html: To which I reply, “true, so you’ll need to find a way to strip them out for epub because epub can’t make that text disappear as easily”
  • I don’t want to have to type numbers in front of all the headings: To which I reply, “yeah, that’s a hassle.”

Ultimately, there are no perfect solutions to this workflow problem, but I hope this alternative may be helpful to some of you.

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Eugene says:

    Fiendishly clever… I like.

  • Dan Rodney says:

    Very clever. Here’s a slight twist on the idea. Let’s assume the sections are on different pages (which is a little different than the above example in which there can be multiple sections on a single page).

    I didn’t test this, but I think it should work: Instead of typing numbers in directly, use a section marker instead. You could do a single find change to add the section marker before each heading. Then you’d only have to change the section marker on the first page of each section.

  • Jongware says:

    Dan, it wouldn’t work in conjunction with the GREP styles. The GREP styles would only see the same ‘character’ at the start of a header: a section marker code.
    Unfortunately, the same applies for “Automatic” numbered lists — in that case there isn’t even a code, as it’s a paragraph attribute.

    I agree with David; you need to manually add something and have the rest done automatically, or you are bound to apply everything by hand.

    If you prefer invisible codes (and don’t mind barely be able to see what you’re doing), you could insert a sequence of a code such as “End nested style”. In that case, have the GREP style scan for “^~h[^~h].+” and add another “~h” at the start for every next color.

  • “To which I reply, ‘yeah, that’s a hassle.'” LOL

  • Lindsey Thomas Martin says:

    I wonder if this technique could be adapted to interpret imported text marked up with Markdown or Multimarkdown?

    LTM

  • Jongware says:

    Lindsay, I bet you can go pretty far with that — see David/Claudio’s Using GREP Styles to Format HTML Code in InDesign — but an alternative could be my way: interpreting a substantial subset of MD straight into InDesign: markdownid.

  • Kir says:

    Great that you’ve figured out a work-around for this but really I think this would introduce more problems in our documents than it would solve. Please keep working on a script for varying heading colours by section – we do this a LOT, and end up with a huge list of heading styles which we have to apply section by section. I have put in a feature request with Adobe…

  • Tushar Chaudhari says:

    Thanks i was finding this type of options all the ways, thanks once again it will help me more!!

  • >