is now part of CreativePro.com!

Controlling Line Breaks With Data Merge

11

One of the limitations of Data Merge is its ability to control line breaks within a field. What if you’re pulling data from a CSV file and want the content of one field to be split across a few lines?

The most obvious workaround is to use a special character in your CSV file, then to run a grep search to replace that character with a line break. But that involves an extra step and requires you to run the data merge beforehand.

There’s another way that will give you control over the line breaks based directly on the content of your CSV file—you just need to do a little tweaking. In this example, we want to have the “time” and “menu” fields break across a few lines:

line breaks in data merge

Here’s how to set it up.

line breaks in data merge
1. Open your CSV file and locate where you want your line breaks to be. Add a double space where you want the line to break.

line breaks in data merge
2. In InDesign, add a new character style called “LineBreak” and give it a tracking value of 10,000. Make sure everything else is left blank.

line breaks in data merge
3. Create or edit the paragraph style you’ll be using along with the variable data. Add a new GREP style. Under “Apply Style,” choose your LineBreak character style and enter two spaces into the text field.

line breaks in data merge
4. The outrageous tracking values will shove anything after those spaces onto the next line. If it’s not enough, you may need to use three or four spaces instead of two. Remember to adjust your CSV and GREP style.

line breaks in data merge
5. The nice thing is that you can still left align, right align, or center your text correctly. This also works in tables.

There are obviously limitations to this approach, but for a basic workaround it’s saved me some time and a few headaches. I’ve found this especially useful when centering the vertical alignment of text that may or may not have more than one line in a variable data field.

 

  • I saw a similar trick on YouTube https://youtu.be/zaPnChlt0rE but your technique is much cleaner.

  • Nicolas Levet says:

    Hello,

    very clever trick, and by the way thanks for the knoweledge on dinosaurs’ diet I was afrain mine would starve of get obese.

  • Tomasz Nowak says:

    Really nice trick.Thanks for sharing!

  • Pierre-Louis André says:

    Não entendi qual o ganho de produtividade. Se devo editar manualmente o arquivo CSV (adicionando dois espaços) por que não edito manualmente diretamente o inDesign (adicionando as quebras de linhas)?

    Google Translator (sorry):
    I did not understand the productivity gain. If I should manually edit the CSV file (adding two spaces) why do I not manually edit inDesign directly (adding line breaks)?

    • David Blatner says:

      Pierre-Louis: That is a very good point. In general, when talking about this kind of data publishing, the productivity gain does not come if you have to perform this only once — it is when you have to do this same thing many times.

    • David Blanchard says:

      The advantage I’ve found is being able to do this while still linking to the CSV file. You can add line breaks only if you run the data merge first, but then you lose the link. I personally find it nice to keep it directly linked to the CSV so that any changes stay live.

  • Ashwin Bali says:

    Really helpful, many thanks for sharing.

  • rafa says:

    In that case (of the example) I would prefer to separate in the excell this 3 thing using the “Data> Text to column “.

  • George McGavern says:

    Four and a half years later, and this work around is still relevant. Thank you for posting this excellent tip!

  • NeM EMANON says:

    Very interesting, but I have an issue, this come with a strange behavior :

    “This is an example of text. This is a whole new line.” (notice the “space space” at the end).

    This give me :

    “This is an

    example of text.

    This is a whole new line.”

    So, obviously, it works, but… Well… The word “example” could be after the word “an”, there is space for it.

    “This is an example

    of text.

    This is a whole new line.”

    I tried to modify the “ragged lines” checkbox, but it changed nothing =/ .

    Any idea ?

  • >