# Using needspace for every paragraph with LyX

I am using 2.0.5.1 on a windows XP OS. I have MikTeX 2.9 installed.

I am trying to use the `needspace` package. As such I have opened MikTex installed it , then refreshed FNDB via the 'Settings' in admin mode.

I then open LyX, load my document and have entered

``````\usepackage{needspace}
\needspace{5\baselineskip}
``````

in the preamble and hit the 'reconfigure' option in Lyx.

Problem is it appears that Lyx does not 'register' the `needspace` package as my lines are running over pages etc.

My question is how would I apply the `\needspace{5\baselineskip}` to the whole document so that LyX knows that I dont want paragraphs drifting between pages...either the paragraph stops before the end of a page or starts on a new page if the space is less than 5

• You need to place the `\needspace{5\baselineskip}` LaTeX macro where you need it, not in the preamble... – Werner Aug 16 '13 at 6:27
• Thanks for reply ...is there anyway of applying this to the whole document ?? it seems like I could just use 'clear page' or something ?? – barsil sil Aug 16 '13 at 6:40
• Note that you do need to run reconfigure in `LyX` after you add a package but (assuming you already did that) running reconfigure after you edit the preamble does nothing. – scottkosty Aug 16 '13 at 8:29
• @barsilsil So that @Werner sees your message, you need to address it to him. Put `@Werner` at the start of your comment. – scottkosty Aug 16 '13 at 8:30
• @Werner Thanks for reply ...is there anyway of applying this to the whole document ?? it seems like I could just use 'clear page' or something ?? – barsil sil Aug 16 '13 at 9:31

Using `\needspace` before a paragraph can't be done with `\everypar`, because the tokens in `\everypar` are inserted after the paragraph has started.

You need to set `\clubpenalties`, rather than `\widowpenalties`, if you want that a paragraph is split across pages only after the fifth line:

``````\clubpenalties 5 10000 10000 10000 10000 0
``````

and, of course,

``````\raggedbottom
``````

With the first line (in the document preamble), TeX will insert infinite penalties between the first five lines, and no penalty after the fifth line and onwards. The normal setting of `\clubpenalty` will be overridden, but not the setting of `\widowpenalty`, so this will discourage splitting before the last line nonetheless.

The `\raggedbottom` declaration is in force with the standard classes in `oneside` mode, so it's necessary only for the `twoside` mode, where this setting of paragraphs would be dubious anyway.

• So `\clubpenalities <N> <val1> <val2> ... <valN>` refers to a `\clubpenalty` of `<val1>` if the paragraph is broken exactly after the first line; `<val2>` if the paragraph is broken exactly after the second line; ... `<valN>` if the paragraph is broken exactly after the `N`th line? TeX by Topic just lists `\clubpenalty`. – Werner Sep 17 '13 at 22:28
• @Werner Yes; and the last specification is repeated as many times as needed. This is an e-TeX extension and is not covered in TeX by Topic and the TeXbook, but `texdoc etex` is your friend. – egreg Sep 17 '13 at 22:29