Adding Section Heads in an InDesign Index with GREP
With GREP, it’s never too late to organize content with headers in InDesign
This article appears in Issue 79 of InDesign Magazine.
If you ever have to add section letters to an existing index in InDesign, you can do that quickly using a GREP query.
You use a single query: Find what: ^(\u).+\r(\1.+\r)+ and Change to: $1\r$0. Translation: match and capture a capital ((\u)) at the beginning of a paragraph (^), and then match all following characters in the paragraph (.+) up to and including the return character (\r). Then match a letter that’s the same (\1) as the one we captured earlier, followed by all characters up to the end of that paragraph (.+\r), group that, and find as many as possible of the same (+). In the example above, ^(\u).+\r matches Barbera 14 (and the return character), and (\1.+\r)+ matches all following lines that start with B. And there’s your section.
Now, to insert the section letter (which is the letter we matched by ^(\u)), we replace the section with the letter we captured ($1) followed by a return (\r) and the entire section ($0)—remember that $0 stands for “everything that was matched by the Find What expression.”
If you want to apply a paragraph style to the section letters, e.g., to add some space before and a font style, that has to be done using a very simple, separate query. At Find What, enter ^\u$, and in the Change format panel, enter the paragraph style—in other words, apply a paragraph style to all one-letter paragraphs. Make sure the Change To field is empty, and then click Change All.
The drawback of this method is that it makes a mess of any formatting, such as italics. You can convert formatted text to text tags, insert the section letters, and then convert the text tags back to the formatting.
Commenting is easier and faster when you're logged in!
Recommended for you
IndexMatic<sup>3</sup> Review
The most powerful indexing solution for InDesign just got even better.
Making Catalogs that Work (with Less Work)
Transform your catalog designs from ho-hum to high performing with these tips.
Designing Book Covers in InDesign
Learn how the key to designing a book jacket lies in the execution of the InDesi...
