Adobe InDesign: Removing Unwanted Spaces, Fast!
By Barb Binder
People preparing files for me to place into a page layout program do some very wacky things in their files. Besides being unable to resist formatting their Word files (even though they’ve hired me for formatting) there’s a lot of extra spacing going on that needs to be removed. There’s intentional spacing like the double spaces after sentences (I’m not going to argue with you here—I just challenge you to pick up any professionally-printed publication off your desk and note the sentence spacing) and double hard returns between paragraphs. There’s also going to be unintentional spacing as well—triple and quadruple spaces, tab space space tab sequences, tabs in the middle of paragraphs, hard returns in usual places, and on and on and on. I want all of these spaces out before I begin laying out a new document.
It’s tough getting people to change their typing habits, so what’s a girl to do? I find it easiest to accept the files they way they were submitted, and then run a series of Find/Change sequences on them to clean them up and get them ready for my formatting. This works in any page layout program, from FrameMaker to Quark to InDesign. However, InDesign has added some GREP pattern queries to the Find and Change dialog box for this exact scenario, beginning with InDesign CS3. Here’s the best part: you don’t need to know what GREP means (General Regular Expression Print) or how it works. Try it:
- Place all your files into the InDesign document. (I place stories on the Pasteboard when I’m not ready to place them on the actual pages.)
- Choose Type > Show Hidden Characters so that you can see the spacing indicators.

- Chose Edit > Find/Change.
- Drop down the Query list on the top line and run each of these queries with the Search parameter set to Document (to search all the stories in the InDesign document):
- Multiple Space to Single Space. In lieu of running a series of searches to weed out all extra spaces, I can now just pick this one preset. The Find What line looks very scary, so just don’t look too closely. If you can’t look away, just understand that it’s a string of GREP characters that looks for two or more spaces (i.e., em spaces, en spaces, flush spaces, hairspaces, etc.) and replaces with one spacebar space. Hit Change All and poof! All extra spaces are gone.

- Multiple Returns to Single Return. Another preset, this one pulls out all the extra carriage returns and replaces with one.

- Remove Trailing Whitespace. Trailing whitespace refers to one or more spaces at the end of a paragraph, between the final punctuation and the hard return(s). Most of the time these spaces don’t cause any problems, but sometimes they don’t fit on the same line as the punctuation and they force a new line or even a new page. For long documents, this can be a real nightmare. This query also picks up the double returns and even multiple spaces (but only when the spaces are at the end of a paragraph) so I tend to run this one first.

- Multiple Space to Single Space. In lieu of running a series of searches to weed out all extra spaces, I can now just pick this one preset. The Find What line looks very scary, so just don’t look too closely. If you can’t look away, just understand that it’s a string of GREP characters that looks for two or more spaces (i.e., em spaces, en spaces, flush spaces, hairspaces, etc.) and replaces with one spacebar space. Hit Change All and poof! All extra spaces are gone.
You may find you need some additional queries to deal with the spacing issues in your own files. For a compete list of the GREP search characters, see http://help.adobe.com/en_US/InDesign/6.0/WSa285fff53dea4f8617383751001ea8cb3f-6f59a.html) Give it a shot! Once you figure out the pattern that you need, don’t forget to click the little diskette button next to the Query list so that you can save your query for future document clean-up.

Hello,
To complete this interesting post, we can remove unwanted spaces between double characteres as parenthesis, braces, brackets, etc. with a lookbehind and a lookahead :
(?<=[([{])\s+|\s+(?=[])}])
In this example, the lookbehind (?<=) looks, in a character class [ ], for an open parenthesis or an open bracket or an open brace followed by one or more spaces. The lookahead (?=) looks for closes characteres preceded by one or more spaces.
@Laurent Tournier
Thank you for sharing, Laurent.
Why did you not post the text string from the first Grep example?
Hi Mrolfer: the GREP strings in all three examples are shown as screen shots under the instructions. If you can’t see them for some reason, you can access all three by opening up the Find/change dialog box in InDesign CS3 or CS4. ~Barb
WOW, what a relief to find such a piece of information while you ere desperately looking for it!
Thanks Barb
So glad it helped, Abdul!
~Barb