"Keep with next paragraph", but ignore paragraphs that are blank lines

Let’s say the document I am currently working on is a style guide for some programming language, and the “recommended” block (both “not recommended” and “recommended” blocks are one-liners) has moved on the next page:

image

(To separate paragraphs, I use empty lines.)

As you can see, Writer has moved the block with the “good” code to the next page, since there was not enough space for it.

Of course, this looks ugly, and of course, I can create a paragraph style with a name, for example, “Example Label”, enable “Keep with next paragraph” option for this style, apply this style to “Not recommended” and “Recommended” lines, and this will solve the problem.

But in fact I often prefer to use as few styles as possible (see image 2), and so I would prefer to use only three styles: Heading 1, Text Body, and Preformatted Text (gray blocks).

image

If I enable “Keep with next paragraph” to the Text Body style, the document will behave very strange: enabling this option for the “main” paragraph style is not what Writer expects from us.

So in fact I need this option to ignore empty lines. Instead of “Keep with next paragraph”, I need the option that will work like “Keep with next paragraph, except if the paragraph is the empty line”.

Do you understand what I mean? Is it possible?

Why don’t you increase the below paragraph spacing of your Preformatted Text to that of an empty paragraph, but then also tick the box Do not add space between paragraphs of the same style?
You can then have two paragraphs of Preformatted Text, one below the other but with normal line spacing (these will split across a page). If the next paragraph is Text Body you will get the “empty paragraph” spacing that you want but without an empty paragraph.
You can set Text Body to keep with next paragraph (normally a very bad idea as it causes big problems) as long as there is not too much Text Body text before some Preformatted Text which must NOT have Keep with next paragraph set.

I have attached a sample where you can see what I mean but also it shows the problem of setting Keep with next paragraph in paragraph style Text Body, see the last page.
PreformattedTextNoSpacing.odt (11.8 KB)

1 Like

The only difference between picture 1 and 2 that I can see is that you left out the boldface in picture 2 and didn’t add color to the x and v marks. The font size is still somewhat bigger than for the code. So, when you say that you want to use as few styles as possible, do you mean keep your formatting as plain as possible (little different formatting), or do you really want to use as few styles as possible? Remember that you can use many styles with exactly the same formatting definitions. You can have character styles called French, German, that only set a different value for the text language in the style definition, but keep font and style the same. You may want to use the same formatting for quotations and code samples, but use different styles for them, so that if you ever want to change the formatting for one, you only have to modify that style. Styles are your friends. You can’t have enough of them. And even if you want to have as few as possible, there’s always the possibility that you have one less than you need.
Adding space below or above a paragraph in the style definition is great, but there is one disadvantage in the implementation in Writer: you can’t suppress space above a paragraph when it’s at the top of the a page, where you don’t want and don’t need it to separate the paragraph from the text above.

New pages, perhaps? I mean Ctrl+Enter.

New pages, perhaps? I mean Ctrl+Enter.
I meant a page, corrected original.

A document should never contain empty paragraphs.

A document is made of paragraphs, each providing some “coloured” information. An empty paragraph contains no information and has no semantic value. Consequently it should not be typed.

The only exception to this rule is within pre-formatted blocks of text. And even there, you must question yourself if lines have a strong semantic meaning or if the only the block as a whole is significant.

A paragraph is “coloured” by the importance you give it. The “colour” is the significance you want to communicate to a reader (or try to). This is done with styles. The primary role of a style is not to format text but to flag text into various categories: heading, comment, citation, example, bulk text.

Therefore your attempt to minimise the number of styles per se is not a good approach for you as an author. Your discourse can be classified in a certain number of categories:

  • text structure through headings, then the Heading n family is your friend
  • programming examples: a good choice is Preformatted Text, but you must decide if every line is important (you terminate it with Enter) or if the block is the target of your demonstration (you terminate every line except the lasst one with Shift+Enter so that you have a single paragraph – and this could give you a better looking document with widow/orphan control)
  • inline headings, suc as “Recommended”, with Example Label style
  • citation
  • comment
  • main text without specific intent, your main topic: Text Body

Of course, you should minimise these categories but don’t merge them into the same style. Keeping separate meanings into separate styles will simplify formatting your document and tuning its layout.

Some styles may end up looking exactly the same, but having separate styles allows you to change your mind about it.

And what I write about paragraph styles is valid for character, page and frame styles. The only golden rule is avoid direct formatting as it will always play nasty tricks on your back when you expect it the least.

Among the worst direct formatting usages is typing empty paragraphs to achieve vertical spacing. This betrays the fact you didn’t think thoroughly about your layout. Vertical spacing should be included in spacing above and below properties of paragraph styles.

You may be tempted by empty paragraphs for the cover page(s). Don’t do this. There are plenty styles dedicated to cover pages, such as First Page page style and Title, Subtitle paragraph styles. Customise them to fit your needs.

Without empty paragraphs, there is no point in caring for them in relation with Keep with next paragraph.