In one of my earliest posts on this blog, I demonstrated a technique that would make text of varying sizes fit a given space, using InDesign’s GREP styles feature.

How it worked – in a nutshell
In short, the type had a base paragraph style with a large point size, but also had several GREP styles that would activate when the line length reached a given amount. For example:
- if the line length was six characters, apply the GREP style that had a point size suitable for six characters;
- if the line length was nine characters, apply the GREP style that had a point size suitable for nine characters, etc.
Can this be done without GREP styles?
Yes, but it employs a different technique. Instead of using GREP styles that would activate based on the character length, the technique uses:
- Several fields in the database;
- Several placeholders in InDesign; and
- A formula in the database
Setup the InDesign File
Using the previous example that had a Data Merge setup, I’ve stripped out the GREP styles and Character styles, so that all is left is a paragraph style.

In this example, I’m going to use three different sizes for the following character lengths:
- Four or less characters;
- Between five and eight characters; and
- Nine or more characters.
I’ll change the document so that there are now four layers:
- The static background with the graphic, being the lowest layer;
- A copy of the name on a layer called 4 less;
- A copy of the name on a layer called 5-8; and
- A copy of the name on a layer called 9 more.

Hiding layers 4 less and 5-8, I’ll go to the 9 more layer and type the letter M 9 times to make sure it fits. I’m using the letter M here as it is a wide letter, so I know that any record from the database (that will appear in the later merge) won’t be longer than this string of letters. I’ll give this a paragraph style of 9 more.

Satisfied with this, I’ll hide this layer and turn on 5-8 and type the letter M 8 times to make sure it fits. I’ll give this a paragraph style of 5-8.

Again once I’m satisfied, I’ll hide this layer and turn on 4 less and type the letter M 4 times to make sure it fits. Again, I’ll name this paragraph style 4 less.

All layers have now been applied. However, if I turn on all text layers at once, it doesn’t make much sense.

That’s fine for the moment, despite the appearance. Onto the next portion of the technique.
Set up the database
As stated earlier, this technique requires additional fields in the database. Let’s look at the database first.

From here, three more columns need to be added, and they are given names that will identify them easily once back in the InDesign file, specifically:
- name1-4
- name5-8
- name9

In the blank cell underneath the field name name1-4 and to the right of the first name (Cell B2 of this example) I’m going to add the following Excel formula:
=IF(LEN(A2)<=4,A2,"")
This formula breaks down to the following:
If the contents of this cell are less than or equal to four characters in length, take whatever was in cell A2 and repeat it here. If not, leave the cell blank.
Upon pressing enter, nothing happens.

That’s intentional and working as designed. In this example, the word Sophia is six characters, so the formula is behaving as expected.
In the blank cell underneath the field name name5-8 and to the right of the formula that was just created, I’m going to add the following Excel formula:
=IF(AND(LEN(A2)>=5,LEN(A2)<=8),A2,"")
This formula breaks down to the following:
If the contents of this cell are between five or eight characters in length, take whatever was in cell A2 and repeat it here. If not, leave the cell blank.
Upon pressing enter, the name Sophia now appears in the cell.

Again, everything is going to plan. Because the name Sophia is six characters long and fits the rule that it is between 5-8 characters long, it appears in the cell.
Lastly, the blank cell underneath the field name name9 and to the right of the formula that was just created (that now has Sophia in it) I’m going to add the following Excel formula:
=IF(LEN(A2)>=9,A2,"")
This formula breaks down to the following:
If the contents of this cell are more than or equal to nine characters in length, take whatever was in cell A2 and repeat it here. If not, leave the cell blank.
Upon pressing enter, nothing happens.

Once again, this is completely expected. This row is now behaving correctly and having the name only appear in the column that relates to how many letters it contains.
I then copy the cells B2 through D2 all the way down the database and watch the rest of the database populate, with the names now appearing in their appropriate columns.

I’ll then save this excel file, but importantly will also save it as a TXT file so it can be taken back into InDesign.
Back to the InDesign File
Because the file I started with was already a data merge file and all I’ve done is update the data, I’ll update that previous data merge data that I had by navigating to the Data Merge Panel, clicking on its hamburger icon and selecting Update Data Source. (If no data had been placed yet, I’d instead use the Select Data Source… option, and navigate to the text file that was just exported).

My data merge panel now has three additional fields that weren’t there before:
- name1-4
- name5-8
- name9
With these fields now available, I’ll now apply them to their appropriate layers, starting with 9 more. I’ll turn the other two text layers visibility off but leave the background visible. I’ll select the 9Ms and replace it with the new field, name9.

Once applied, I’ll hide layer 9 more and make layer 5-8 visible. I’ll then highlight the 8Ms and replace it with the new field name, name5-8.

Lastly, I’ll hide layer 5-8 but make layer 4 less visible. I’ll then highlight the 4Ms and replace it with the new field name, name1-4.

Unlike the other fields, I can’t see anything here. That’s because the text has overset because the field name is too long, mainly because of the chevrons.
Bonus tip to hide the chevrons
The field indicators in Data Merge (the chevrons) can be really annoying, but thanks to GREP styles, we can make them less annoying. With nothing selected, I’ll start by making a character style called go away chevrons. It will have the following properties:
- size: 1 pt
- char width: 1%
- char height: 1%
- colour: [None]
Because the chevrons are only affecting the 4 less layer and style, I’ll adjust the paragraph style to contain a GREP style that will apply “go away chevrons” to this style only. I’ll edit the 4 less paragraph style, and once in the Paragraph Style Options dialog box, go to Grep Style in the left hand column, then click the New GREP Style button, apply the style go away chevrons and in the To Text: field, I’ll add the following phrase:
[<|>]

Bonus tip over – Back to the InDesign File
The chevrons are now hidden, but the preview is still pretty tight. To ensure the text comes in without oversetting, I’ll left click on the text frame with the black arrow tool, right click and select Text Frame Options

I’ll go to Auto-Size (fourth item down) and from the Auto-Sizing Dropdown, select Width Only and provide a minimum width, in this example being 80mm.

The text and layers now have all their formatting applied. I’ll turn all of the layers on now, but it still looks like a hot mess.

For the last part of the technique, go to the Data Merge palette and turn the preview on.

Et Voila!
Would this work outside of InDesign?
With the exception of hiding the chevrons, the technique does not use GREP styles, so yes – it is able to be applied to in other applications.
In the next Colecandoo article, see how this technique can be applied in other applications, particularly to take advantage of techniques that cannot be applied in InDesign.
Here are some examples of what will appear in the next post:








