Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
1  
You write that "The problem is, sometimes \cleardoublepage inserts a blank page twice." Please provide an MWE (minimum working example) that replicates this problem behavior. –  Mico Jun 25 '12 at 1:44
    
Thanks for the comment, @Mico - unfortunately, as I already stated, I tried coming up with an MWE, but I cannot replicate the problem with an MWE... I did come up with some sort of a solution (posted below) - but I'd still like to know if there is a single command that can "reset" the top position of current page, without inserting a page break. Cheers! –  sdaau Jun 25 '12 at 2:20

1 Answer 1

Ok, FWIW (without a proper MWE), I fixed my problem with \unskip (as I heard somewhere it resets skips), and \vspace* - but the question for a command that "resets the top" still stands.

First, I tried inserting an \unskip instead of the problematic \cleardoublepage; that produced "problematic" page section measurements of:

% t=28.68004 g=591.5302 b=10000 p=0 c=100000#
% t=3.51996 g=591.5302 b=10000 p=-300 c=100000#
% t=49.59358 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#

So, I get a 3.51996 (nicely, without plus or minus components); and for proper alignment, I should have -10.76009; so I take I need 3.51996-(-10.76009) offset upwards, so I simply enter this sequence instead of the problematic \cleardoublepage:

...
\unskip
\vspace*{-14.28pt}
...

... and now the (final) page measurements are:

% t=14.40004 g=591.5302 b=10000 p=0 c=100000#
% t=-10.76004 g=591.5302 b=10000 p=-300 c=100000#
% t=35.31358 plus 0.15234 g=591.5302 b=10000 p=0 c=100000#

There is but 0.0004 pt difference, and visually I cannot see it - so I'm ok with this.

Another thing is that the mentioned \mysection is actually a titlesec custom sectioning command; and another thing I didn't mention above, is that the sequence more accurately looks like this:

\newcommand{\SetMyVar}[1]{%
\def\MyVar{#1} % 
}

...

\includepdf{...}
\cleardoublepage

\SetMyVar{1}
\tracingpages=1
mysection*{Section X} \tracingpages=0

....

(yes, the \SetMyVar macro is that trivial - it's simply for syntactic consistency with other macros I use)

Now this is the trick - if I replaced the \cleardoublepage "as is" - like this:

\includepdf{...}
\unskip
\vspace*{-14.28pt}

\SetMyVar{1}
\tracingpages=1
mysection*{Section X} \tracingpages=0

... I could in fact not see any expected displacement in the logfile! However, when I then placed the \cleardoublepage replacement after the \SetMyVar macro call:

\includepdf{...}

\SetMyVar{1}
\unskip
\vspace*{-14.28pt}
\tracingpages=1
mysection*{Section X} \tracingpages=0

... then finally it started working - and I got the (final) page measurements mentioned above.

I still wish I could reset with a command, instead of "compensating" "manually" - but as long as this approach keeps on working, I'll be happy :)

Hope this may help someone,
Cheers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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