I'm experimenting with typesetting "pull quotes" using wrapfig and noticed some strange behaviour. Under certain conditions, having a wrapfigure at the beginning of the first paragraph after a new section (subsection, etc), LaTeX will sometimes break the page between the section header and the following text/wrapfigure block.
This is of course unacceptable. Any ideas how to prevent it? (The page break also destroys spacing in the wrapfigure, remove the \lipsum[1-4] for comparison.)
MWE
\documentclass{article}
\usepackage{tikz}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
sdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf lksdjf klsdf
sklfjsa dklf sdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf lksdjf klsdf
sklfjsa dklfsdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf lksdjf klsdf
sklfjsa dklf sdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf lksdjf klsdf
sklfjsa dklf sklfjsa dklf sdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf
lksdjf klsdf sklfjsa dklf sdjfkljsdf kjsd kdsfj sadlkfj sdjfskldf lskdjf
lksdjf klsdf sklfjsa dklf sklfjsa dklf
\section{Section}
\begin{wrapfigure}[5]{R}{50mm}
\fontsize{13}{17}\selectfont\vspace*{-10pt}
\hspace*{4pt}\begin{tikzpicture}
\node[anchor=north east,inner xsep=1pt] at (0,12pt) {\fontsize{32}{32}\selectfont''};
\node[anchor=north west,text width=40mm, align=left, inner sep=0pt] at (0,4pt) { Pull quote for a nice touch };
\end{tikzpicture}
\end{wrapfigure}
\lipsum[1-2]
\end{document}
\pagedepthcontains the depth of the section heading's box? And\maxdimenis just 16383.99998pt, so what does\pagedepth\maxdimenchange precisely? I mean, it works perfectly, but I'd like to know why. :) – Wouter May 04 '17 at 11:40\pagedepthis an internal register that tex updates as things are added to the page, so it's only a very transient setting, but it lasts long enough to be in force at the start ofwrapfigcode where it checks to see if it is near the bottom of a page and if so it forces a page break. So any value close to or more than\textheightwould do,\maxdimenis overkill but works whatever the page size is. – David Carlisle May 04 '17 at 12:54\pagedepth\maxdimenactually change the value stored in\pagedepthto that of\maxdimen? When I first found your answer to this question I just assumed it did and that the section head got pushed to the next page because its 'box' then looked deep enough forwrapfigto wrap around. But upon actually thinking about it, in my limited interpretation, I would expect it to evaluate simply to something like15pt16383.99998pt. I feel like I'm missing a crucial understanding here. – Wouter May 04 '17 at 21:19wrapfig:\ifdim\@tempdimb<\z@ % \WF@info{Page overfull already;}%to decide that there is not room on the page. – David Carlisle May 04 '17 at 21:22\setlengthand the like. Is this not the case? Or are internal registers like\pagedepth, or indeed justpagedepthitself, different in this regard? In general, can you perhaps point me to a central resource to read about all of these internal workings of TeX and LaTeX? – Wouter May 04 '17 at 21:26\setlength,\setlength\zz{...}is just a simple macro that expands to\zz=...Knuth's texbook is the definitive reference for pagedepth etc. – David Carlisle May 04 '17 at 21:28