I've been using \needspace{4\baselineskip} to keep Poem Titles with a graphic produced by lilypond-book (music typesetting engine) together. In a 184p. document with 79 different Poem Titles followed by graphics, this rule is broken about four times, leaving the title at the bottom of one page and the music on the following page. Is there a way to further insist that the rule is never to be broken?

bad page break

Also, if the \verselength is set to where long lines are broken and indented, the broken-indented part of the line occasionally finds itself on the other side of a page break, which is never ok either. Another bad page break

The poem lines alternate between \\* and \\, with the last line of a stanza \\! - this rule is also broken on rare occasion (perhaps in this example because of the \needspace{4\baseline} before the Poem's Title):

Bad Page break again

The minimum code required to reproduce this is a bit of a challenge given all the different elements at play. The whole code is available here: http://code.google.com/p/lypsautierant/source/browse/#svn%2Ftrunk%2Fpsautier, and if a specific part of the code would be helpful I will provide it. I am hoping that there is something global that forces latex (xetex) to always and without exception obey page breaking rules that have been made explicit - perhaps breaking in other places latex considers absolutely undesirable.

2 Answers 2


Too much code in your link to try, But You probably don't need needspace, just setting infinite (ie 10000) penalties after the title and (depending on style) the first rows of the music/poem ought to be enough as long as there is enough flexibility on the page to compensate for not breaking at that point. For example if \flushbottom is in effect.

If every possible break point is infinitely bad TeX will pick one of them. It is really better to arrange that that is not the case, but it is the case and you want to stop TeX breaking the page, you can put the title and the first line in a box. Boxes never break.

  • thanks for the tips. I tried all sorts of combinations of penalties and it always ended up leaving a lot of Titles at the bottom. I went back to needspace and for some reason now there is only one exception which isn't too bad to fix manually. Here is another thought: it is not out of the question to leave an entire page blank, or with some kind of image in places where it would help the layout. Is there a way to tell latex it can insert a blank page, or a page with an image on it, if it will help decrease the badness of page breaks?
    – ftherese
    May 16, 2013 at 20:11
  • @ftherese A full blank page won't help page breaking, the badness (or not) of the pages before and after would be the same. May 16, 2013 at 21:21

There are a couple ways to approach this. Which one you use will depend on your layout priorities and how much you know about your content.

You could just use a really big hammer:

    % poem  title stuff
    % music
    % extra verses

That should be pretty self explanatory. You wrap the content that needs to stay on the same page in an environment that makes it so. This approach is quick, dirty, and gets the job done for a lot of cases; yet I do not recommend it for your document. Using a such a big hammer will place arbitrary restrictions on your content and output options.

  • What if you add a piece that is long enough it really does need to span two pages?
  • What if you want to print in a booklet format using half size pages? Or run a large-print edition?

The big hammer approach can make a big mess in scenarios like these.

With a little more finesse, you can massage the content by giving latex formatting suggestions that keep your preferences in mind but allow the layout engine to make some compromises when it really needs to.

Using \needspace implies that in every case you know what content is coming next. You mention the case of knowing that four lines are coming up in an extra verse but sometimes a line will wrap. This and many other scenarios make it an fickle tool for laying out a large document. Instead I would review the various pagebreak related penalty values. This answer has a useful run down of the basics.

I would suggest laying out your content something like this:

% Redefine lilypond function to highly suggest
% _not_ breaking pages between systems

% If we are going to break, best to get it over with before we start
\section{poem title}

% Don't ever break between a poem title and the first system

% Keep extra verses together, but allow breaks between verses
% only if they _must_ happen somewhere
    % verse data

    % verse data

% Once we get through a whole poem would be a great place to break

You can adjust to taste, but using 3 as both the suggestion and penalty value for breaks sets a very strong preference for keeping all the parts of a poem together while still allowing the layout engine to split out parts that would otherwise just run off the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.