Controlling Line Breaks With Data Merge

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:
Here’s how to set it up.
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.
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.
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.
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.
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.
This article was last modified on July 20, 2021
This article was first published on March 27, 2017
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 ?
Four and a half years later, and this work around is still relevant. Thank you for posting this excellent tip!
In that case (of the example) I would prefer to separate in the excell this 3 thing using the “Data> Text to column “.
Really helpful, many thanks for sharing.
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)?
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.
Compreendi. I understood!
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.
Really nice trick.Thanks for sharing!
Hello,
very clever trick, and by the way thanks for the knoweledge on dinosaurs’ diet I was afrain mine would starve of get obese.
I saw a similar trick on YouTube https://youtu.be/zaPnChlt0rE but your technique is much cleaner.