This is one of the cases, where I've tried for some time now to come up with a minimal example that will demonstrate the problem, but I can't. All I can provide is the problematic behavior of the master document, so I hope you'll bear with me.
Essentially, I use titlesec
for custom headings; and pdfpages
to include PDF pages. I have a structure like:
\includepdf{...}
\cleardoublepage
\tracingpages=1
mysection*{Section X} \tracingpages=0
% rest of content...
When it's like this, all is good, and I can confirm that all sections are positioned at the same location on the page (EDIT: a good explanation of the \tracingpages
log is in #60213 - How can I create a chapter with graphics only divided into different sections?):
$ grep '^%' mydocument.log
%% goal height=591.5302, max depth=5.5
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
%% goal height=591.5302, max depth=5.5
% t=0.0 g=591.5302 b=10000 p=0 c=100000#
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
%% goal height=591.5302, max depth=5.5
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
%% goal height=591.5302, max depth=5.5
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
So, all sections end at top position t=35.31354, and they are indeed aligned fine.
The problem is, sometimes \cleardoublepage
inserts a blank page twice.
If the included pdf ends on odd page, then \cleardoublepage
correctly inserts a blank page, and new section starts on next odd.
If the included pdf ends on even page, then I get a blank on (next) odd page; \cleardoublepage
apparently picks this up, and inserts one more as even - and the new section starts on (next+2) odd page.
So if I remove \cleardoublepage
from a spot like that, then the next "Section X" starts at the next page after PDF is finished, and is on an odd page, as expected - but now the title is slightly misplaced vertically ( :/
) ; here is what the log reports:
%% goal height=591.5302, max depth=5.5
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
%% goal height=591.5302, max depth=5.5
% t=0.0 g=591.5302 b=10000 p=0 c=100000#
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
# NOTE NO 'goal height' HERE!!
% t=40.68004 plus 4.0 minus 6.0 g=591.5302 b=10000 p=0 c=100000#
% t=15.51996 plus 4.0 minus 6.0 g=591.5302 b=10000 p=-300 c=100000#
% t=61.59358 plus 4.15234 minus 6.0 g=591.5302 b=10000 p=0 c=100000#
%% goal height=591.5302, max depth=5.5
% t=14.4 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76009 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31354 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#
So obviously the third listed part is the problematic one:
- There is no
%% goal height
- as if a new page never started; - The first top position reported is
40.68004 plus 4.0 minus 6.0
, unlike the others being 14.4 - The top then seems to "reset" itself to 15.51996 - but it needs to be on -10.76009 to align like the others.
To me, the problematic part looks like a state, as if we're "currently" on top of a blank page; yet latex still thinks of it as not a new page.
Note that I'm not keen on using \vspace{-Xpt}
or similar to manually correct, since I'd have to tune the value by hand, and the master document takes several minutes to build... (and what guarantee do I have that all eventual problematic sections will be misplaced by the same ammount?)
So is there a command I could use, that could "reset" the "current page", so that the "top position" would be reset to a default value (as a side effect, I'd expect if you use such a command on a page that is typeset halfways, that the "cursor" would essentially go up, and typeset over existing contents)
PS: As an experiment, I tried to get the last statements from \newpage
:
$ texdef -t latex -c book \newpage -f
\newpage is defined by (La)TeX.
\newpage:
macro:->\if@noskipsec \ifx \@nodocument \relax \leavevmode \global \@noskipsecfalse \fi \fi \if@inlabel \leavevmode \global \@inlabelfalse \fi \if@nobreak \@nobreakfalse \everypar {}\fi \par \vfil \penalty -\@M
... and add them instead of the problematic \cleardoublepage
, in hope that they might "reset" the page without breaking it - however, even just \penalty -\@M
on the problematic spot inserts a new blank page (and also \leavevmode
at the same position does nothing to remedy the position)
\cleardoublepage
inserts a blank page twice." Please provide an MWE (minimum working example) that replicates this problem behavior.