5

When using memoir's \vplace environment, I've noticed that LaTeX tends prefer break before a \vplace when its content starts with a \{sub}section.

So for example:

\documentclass[oneside,11pt]{memoir}
\usepackage{lipsum}
\begin{document}
\lipsum[1] % A
\begin{vplace}
  \subsection{Title}  % Starts a new page if the number of pages is > 1
  \lipsum[1] % B
 \end{vplace}
\lipsum[1] % C
\end{document}

When the content is contained to one page it works as expected. When there is more than one page, the break occurs at the Title, even if a visually preferable break occurs after the paragraphs in the vplace.

One can see this by increasing the number of ipsum sections to e.g. [1-2].

The vplace environment is simply defined as:

\newenvironment{vplace}[1][1]
  {\par\vspace*{\stretch{#1}}}
  {\vspace*{\stretch{1}}\par}

This only appears to occur when the vplace starts with a section.

It appears that the vplace environment is not suitable for spanning multiple pages. Is there an environment or alternative that is, or a way to make the vplace macro's page breaking effects more suitable?

3
  • what if \lipsum[1-5]?
    – touhami
    Oct 7, 2015 at 17:12
  • What's the real aim you have in mind? The vplace environment is thought for producing a single page such as a dedication.
    – egreg
    Oct 7, 2015 at 17:13
  • 1
    @egreg – If the content is on a single page (which may be part of a multi-page document), center the content (minus "leading" and "trailing" text); if the content spans multiple pages I want it to behave as-if vplace did not exist, ideally. Does that make sense? Oct 7, 2015 at 17:33

1 Answer 1

2

This is perfectly normal. If I set \tracingpages=1 in the \lipsum[1-2] case, I get in the log

%% goal height=541.40024, max depth=5.5
% t=0.0 g=541.40024 b=10000 p=0 c=100000#
% t=11.0 g=541.40024 b=10000 p=1000 c=100000#
% t=24.6 g=541.40024 b=10000 p=0 c=100000#
% t=38.20001 g=541.40024 b=10000 p=0 c=100000#
% t=51.80002 g=541.40024 b=10000 p=100 c=100000#
% t=65.40002 g=541.40024 b=10000 p=0 c=100000#
% t=79.00003 g=541.40024 b=10000 p=100 c=100000#
% t=92.60004 g=541.40024 b=10000 p=0 c=100000#
% t=106.20004 g=541.40024 b=10000 p=0 c=100000#
% t=119.80005 g=541.40024 b=10000 p=0 c=100000#
% t=133.40005 g=541.40024 b=10000 p=0 c=100000#
% t=147.00006 g=541.40024 b=10000 p=1000 c=100000#
% t=160.60007 g=541.40024 b=10000 p=0 c=100000#
% t=174.20007 plus 1.0 g=541.40024 b=10000 p=1000 c=100000#
% t=187.80008 plus 1.0 g=541.40024 b=10000 p=0 c=100000#
% t=201.40009 plus 1.0 g=541.40024 b=10000 p=0 c=100000#
% t=215.00009 plus 1.0 g=541.40024 b=10000 p=100 c=100000#
% t=228.6001 plus 1.0 g=541.40024 b=10000 p=0 c=100000#
% t=242.2001 plus 1.0 g=541.40024 b=10000 p=0 c=100000#
% t=255.80011 plus 1.0 g=541.40024 b=10000 p=1000 c=100000#
% t=269.40012 plus 1.0 plus 1.0fill g=541.40024 b=0 p=-300 c=-300#
% t=333.49432 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=347.09433 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=360.69434 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=100 c=100
% t=374.29434 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=387.89435 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=100 c=100
% t=401.49435 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=415.09436 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=428.69437 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=442.29437 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=455.89438 plus 7.65746 plus 1.0fill minus 0.94289 g=541.40024 b=0 p=1000 c=1000
% t=483.09439 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=0 p=1000 c=1000
% t=496.6944 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=510.2944 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=523.89441 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=0 p=100 c=100
% t=537.49442 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=0 p=0 c=0
% t=551.09442 plus 8.65746 plus 2.0fill minus 0.94289 g=541.40024 b=* p=100 c=*

Each line in the output records the height of the accumulated material after each typeset line, the goal height, the badness if a page break had to be taken there, the penalty for a break after the line and the “cost” of the break. The “cheapest cost so far” is marked with #. The formula for the cost of a page break can be found on page 111 of the TeXbook.

We see that when \vspace*{\stretch{1} appears, an available stretch of 1fill is shown and also a -300 penalty (it's due to the section title and \penalty\@secpenalty that's issued before it). This produces, according to the formula in the TeX book, a cost of -300. Later costs are larger, so the break is taken after the \vspace{\stretch{\fill}.

In the \lipsum[1] case, the copy fits on one page, so the best cost comes to be the -10000 that's found at \end{document} in consequence of the routine for ending a job.

You get two pages also if you use \lipsum[1-2] at the end, because the copy doesn't fit on one page any more.

Possible solution

Change locally \@secpenalty to be 0.

\documentclass[oneside,11pt]{memoir}
\usepackage{xpatch}
\usepackage{lipsum}

\makeatletter
\xapptocmd{\vplace}{\@secpenalty\z@}{}{}
\makeatother

\begin{document}
\lipsum[1-2] % A
\begin{vplace}
  \subsection{Title}
  \lipsum[1] % B
 \end{vplace}
\lipsum[1] % C
\end{document}

However you still have the stretchable glue that can come into play again.

2
  • Thank you @egreg - this is valuable. One thing that would improve it, if it is possible, is to have any trailing ipsums not be separated by vertical space so that fills the page (i.e. any pages after the first should have the text from B to C appear contiguous). Oct 7, 2015 at 17:58
  • ... though I recognize that such a requirement may be quite a bit more complex than the elegant \@secpenalty change here. Oct 7, 2015 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .