Square Pegs now fit into Round Holes

One hurdle I’ve often encountered with Data Merge is when text fields which have to fit in a given space. Examples may be speech bubbles, headlines or nametags.

Normally, the way to proceed with this variety of project would be to determine the longest word in the database and set the size of the font to fit the longest word. This is fine for large words, but tends to make small words look out of place.

Ideally, it would be nice for the type to fit according to the size of the name, but that isn’t possible… is it? Well, with GREP styles, it is.

This example features a name-badge which contains first names which range between 3 to 11 letters long. The first thing to do is determine how many letters will fit within the given space. To do this, use the widest letter of the font being used (M in this example) and type the letter 3 times until the type fits the box as desired. Now create this as a paragraph style (e.g. Badgetype).

From here, type an additional letter. There will be an overflow warning – this is intentional. From here, use Ctrl-A to select the type and make a new character style called mynameis4. Make sure that the “Apply Style to Selection” checkbox is ticked; and that the “Preview” checkbox is ticked. Within the character style, only edit the Advanced Character Formats and change the items in this panel to distort the type accordingly until the type comes back into view. Once the type comes back into view and appears as desired, click OK.

Now, type another letter and once again an overflow warning will appear. Again, use Ctrl-A to select the type and duplicate the character style to create a new character style called mynameis5. Again, go to the Advanced Character Formats and again distort the type until it appears as desired. Click OK.

Repeat this process until all 11 letters have character styles assigned to them. Apart from [None], there should be 8 character styles from mynameis4 to mynameis11. From here, select all the type again and select the character style [None] to remove the style. The type will overflow once again, but this edit the Badgetype Paragraph style.

From this dialog box, go to the GREP styles options and make a new GREP style. From here, select the mynameis4 Character style; and in the GREP search below, type:

….

(four fullstops)

make another GREP style and select the mynameis5 Character style; and in the GREP search below, type:

…..

(five fullstops)

Repeat this process until all remaining styles have GREP styles associated with them. That is, a seven letter style will have seven fullstops in the GREP search. The only exception is “mynameis11” which will have a “+” after the last fullstop. Click OK once this is done – the GREP styles dialog portion of the dialog box should look like the screengrab below.

If this is done correctly, the type should change size whenever a letter is added so that the type becomes incrementally smaller as type is entered.

To make this work with variable data, simply select the database and then insert the textfield and apply the paragraph style Badgetype to it.

Voila! I have included the PDF used for this tutorial which contains attachments of the InDesign and database files so that people can see exactly how this was constructed.

Advertisements

About colmin8r
A prepress operator since 1997 specialising in Adobe InDesign.

23 Responses to Square Pegs now fit into Round Holes

  1. Pingback: Going beyond “Stencil Letters”… « Colecandoo!

  2. Chris says:

    Ho-Lee Balls… This took me a while to fine tune exactly the way I needed it,but WOW… this is EXACTLY what I have needed… To think about all of the countless hours I have wasted doing this manually… You sire, are a God amongst men.

  3. Pingback: Live Text Masking in InDesign « Colecandoo!

  4. vlad says:

    Interesting trick. I would make one change, to make it more approachable: instead of “….” (for periods, 5 etc) use proper grep repetitions: “.{4}”, “.{5}” etc.

    • colmin8r says:

      Thank you for that. I did think of doing the curly braces trick but as more letters are added, what happened was there would be “leftover” letters that the GREP would not apply to unless the leftover letters were a multiple of the number in the curly braces. Using the fullstops instead works around this issue. To demonstrate this, I have made a quick example that can be downloaded from https://dl.dropbox.com/u/55743036/grepcurlybraces.indd

      • vlad says:

        here is the file, with the fixed style:
        https://docs.google.com/file/d/0B25thAkTFmGZNTBRU0cyV3pxdkU/edit?usp=sharing

      • Alecat says:

        You can do a .{11,} to define “anything of 11 or more” length. I’ve been using this trick in my inDesign files for a while, and my background in Perl programming has been very handy in getting my GREP styles to work 🙂

  5. Christine says:

    Hi,

    I’ve been trying to resize text to fit a maximum frame size but my longest degree name is 50 characters long. Do I have to create 50 character styles or is there a faster way?

    I’m doing a data merge from an Excel spreadsheet to produce degree certificates and most work fine except a few with very long degree names.

    Thanks,

    Chris

    • colmin8r says:

      The initial article was an exaggerated example in a case where there is a small trim size but large letters, but to make headlines fit into a headline space, you can use Alecat’s trick above. That is, make two styles (one without being condensed, one condensed) and use the .{1,35} (this will leave anything under 35 characters long); and then use the .{36,} (this will condense everything over 36 characters).

  6. Christine says:

    Hi,

    So I created two character styles for the degree title, one large and one small. Then I created two GREP styles associated with the character styles, one with .{1,50} and the other with .{51,}. Then when I ran the data merge I got the following message and the text hadn’t resized at all.

    Certificate_test-1
    1) Page 14, 13 chars/1 words f

    What am I doing wrong?

    Tx,

    Chris

  7. Christine says:

    Scratch my previous post. I killed the text box then recreated everything from scratch and it worked! Thank you so much!

  8. Christine says:

    Hi,

    I spoke too soon. The GREP styles worked perfectly and now I’m getting that error message again.

    Certificate_test-1
    1) Page 14, 13 chars/1 words f

    What am I doing wrong?

    Chris

    • colmin8r says:

      it is hard to tell without seeing the file. upload the file to dropbox or a similar service and PM me using the address in the “about” portion of this site.

      • Christine says:

        I actually figured it out by playing with styles. It works well now. Tx.

  9. Dan says:

    Can you leave a mark in the data merge set, such as (just to use an example) an asterisk to denote “this text should be bold” (or perhaps “all the text between these asterisks should be bold”), and then have the style replace the text on merge?

    For example: *Steve* would then render as “Steve” but bold?

    (If so this would save many hours…)

    • colmin8r says:

      If the only content to bold would be Steve then it would be easier to make a GREP to look for the word Steve and change it to bold. Perhaps if you elaborate on exactly what your project involves a solution can be provided.

      • Dan says:

        I’m laying out text for a card game in indesign. I want to be able to make certain text (and it is unique text) bold, certain text italic, certain text semi-bold, etc. What I am doing right now is puttnig in a bunch of codes that I can search for and do a find/replace to change it. So, for example:

        *Ace of Spades*
        The Ace of Spades is a high card. /(It beats all other cards.)/

        (This is not the game I’m laying out :))

        But the idea would be that the text between the *’s would be bold, and the text around the /’s would be italicized. A similar (but not uniform) pattern would be used on all the other cards in the game. Is that clearer?

      • colmin8r says:

        Your method will work, but would work better with XML where the words to be italicised, bolded etc are already tagged. XML into indesign is another issue altogether and is a very steep learning curve too.

        Nevertheless, what you would like to do can be done, it just involves using a “find-between” GREP. InDesignSecrets.com has a page for this: http://indesignsecrets.com/findbetween-a-useful-grep-string.php

        This would involve merging to a new indesign file and then running GREP find/changes on the file.

        As for merging to a PDF and using GREP styles to do the same task, that is more complicated. GREP styles doesn’t remove text, it only formats the patterns it sees. However, you can make a format that gives the text no fill or stroke and sets its width to zero so it looks like there is nothing there.

  10. elgranjoe25 says:

    Es un truco muy interesante. ¡Tengo una pregunta!
    Es posible por medio de un script o estilo GREP adaptar el interlineado de un texto en un marco de texto.

    • colmin8r says:

      (English for those who don’t speak spanish): It is a very interesting trick.I have a question!
      It is possible via a script or GREP style to adapt the spacing of text in a text frame.

      My answer: not really. In-tools programmer Harbs has a page that may help though but it won’t be able to do its tricks during a merge. See his page: http://in-tools.com/article/scripts-blog/fun-with-text-fitting-in-indesign/

  11. Pingback: Pre-Sort Mail Pressure | Colecandoo!

  12. Rex Francis says:

    This is a great article, but the PDF attached doesn’t have a link to the indesign file, as advertised. Pity. Where can I get it?

    • colmin8r says:

      I just checked and the indesign file is definitely there. It may just be in a spot that wasn’t seen. It is an attachment within the PDF, so when viewing the PDF in Adobe Acrobat, look for a little paper clip icon, and there should be three attachments – the font, the database, and the InDesign file.

      I hope this helps.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: