Skip to main content
Participant
February 28, 2013
Answered

How to automatically prevent Widows/Orphans in InDesign

  • February 28, 2013
  • 5 replies
  • 82648 views

Hi,

I constantly create multi-languaged leaflets within InDesign CS5 and the one thing I often find is that I constantly have to revisit the entire document to prevent widows (or orphans - whatever you call them) at the end of a paragraph.

Is there a way to setup within my paragraph style to prevent, lets say, anything less then 10 characters at the end of the paragraph?

I am aware of using the White-Space non break command, but the amount of text I have to visit I wondered if it could be setup in the first instance and prevent widows appearing at the end of a paragraph.

Thanks for taking the time to read

Steve

Correct answer Peter Spier

This comes up from time to time, and usually sparks a discussion about why it might not be adviseable, but I'll dispense with that for now and say that you can create a character style that applies No Break, then use a GREP style to apply it to the last n characters in a paragraph in the GREP Styles section of your Paragraph Style definition.  The expression .{n}$ should work, where n = the number of characters you want to keep from breaking.

5 replies

Dave Creamer of IDEAS
Community Expert
Community Expert
October 14, 2021

I prefer the method that adds the GREP style into the paragraph style. I usually add it into the main Body style so all my derivative, based-on styles pick it up. You just have to change it based on the font size and column width once, rather than remembering to do the find/change.

David Creamer: Community Expert (ACI and ACE 1995-2023)
Peter Kahrel
Community Expert
Community Expert
October 15, 2021

The problem with GREP styles is that they can slow down a document. Every time a story recomposes -- a character is inserted (or deleted), a float is placed or moved, in index marker is added, etc. -- all GREP styles execute. That can cause delays.

 

In addition, a GREP style that keeps a certain number of characters together always pulls characters from the paragraph's penultimate line to the last one. But tightening a paragraph a bit so that the short last line is removed often leads to a better result.

 

P.

Dave Creamer of IDEAS
Community Expert
Community Expert
October 15, 2021

"Slow down" is a relative term. With my system and my documents (that I use it on), I haven't noticed much difference. 

 

Peter K.--question: does ID recompose every paragraph in a story or just the edited* paragraphs?

*Anything causing rewrap, such as edited by user, change in column width, or affected by text wrap upon reflow. 

If the former, it would seem a colossal waste of computing resources.

David Creamer: Community Expert (ACI and ACE 1995-2023)
Peter Kahrel
Community Expert
Community Expert
October 14, 2021

Is there a way to find the only the space before the last word of the paragraph?

\s(?=[^\s]+$)

This one matches only the space before the last word in a paragraph.

P.

Shlomit Heymann
Inspiring
October 14, 2021

Thank you so much! 

Community Expert
April 30, 2021

"…Is there a way to apply a NOBREAK character style without removing a style already applied?"

 

Hi Matthew,

basically no, if you try this "by hand".

 

BUT:

It's different if you apply the two character styles with two GREP Styles using a paragraph style.

Or if you apply the "Bold" character style "by hand" and the "No Break" character style through a GREP Style like Peter Kahrel suggested.

 

IMPORTANT:

There must be no entry for font style in the "No Break" character style.

There must be no entry for No Break in the "Bold" character style.

No entry with a check box means this state: [-] .

 

Regards,
Uwe Laubender

( ACP )

Peter Spier
Community Expert
Peter SpierCommunity ExpertCorrect answer
Community Expert
February 28, 2013

This comes up from time to time, and usually sparks a discussion about why it might not be adviseable, but I'll dispense with that for now and say that you can create a character style that applies No Break, then use a GREP style to apply it to the last n characters in a paragraph in the GREP Styles section of your Paragraph Style definition.  The expression .{n}$ should work, where n = the number of characters you want to keep from breaking.

Participant
April 1, 2014

I created a grep that assigns a NOBREAK character style the last word of every paragraph: (\s\w+.?)$

This should apply the NOBREAK character style to...

a space (\s)

+ word (\w+)

+ optional punctuation (.?) - really any character

at the end of every paragraph ($)

I think my parenthesis are actually optional as well, and I'm sure I could get more specific with the punctuation part too but this seems to the the trick for me.

HBurrows
Participant
December 15, 2015

I searched for an answer to this question, and I found these. I am not following how to create a GREP style. Can someone walk me through that process either by clear instructions or screen shots? I tried a few different things, but I must not be fully comprehending how to do this. TIA

Peter Kahrel
Community Expert
Community Expert
February 28, 2013

To prevent last lines shorter than 10 characters, run this Grep query:

Find what: .{10}$

Change to: <leave empty>

Change format: No Break

Or you can do this as a Grep style.

Widow and orphan prevention is set in the paragraph style, see Keep Options.

Peter

Participant
February 28, 2013

Thats exactly it! Thanks ever so much Peter!