I would like to be able to use an \if
command to check if a \section
appears on the first line of a new page. If a section heading is the first line of a new page, I would like to then adjust some of the spacing between the section heading and the header by modifying \headsep
.
Is there a simple way to do this?
More info (edit): The issue arises whenever you don't forcibly add new pages to separate sections. If you were to write continuously, then, whenever TeX decides to insert a page break, the spacing arguments native to \section
are suppressed iff the page break occurs right before a new section.
Hence, if, for instance, you have long, ruled headers, the lack of spacing looks odd:
As far as I know, TeX doesn't have a built-in counter for line numbering that can be used to check if a heading appears on the first line of a new page. You don't know when a page break is likely to occur, either. Thus, although I have a specific purpose for finding a way to check if something is on the first (or nth line) of a page, it might still help others with different purposes.
lineno
,fancyhdr
, andcolor
packages, so it is not an elegant solution by any means. First initiatelineno
to insert line numbers to your document;lineno
adds a counter calledlinenumber
which you can reset for every new page by adding \@addtoreset{linenumber}{page}.fancypagestyle{y}
that adds the x shift\setlength{\headsep}{x}
Then, when you define your\def\@makesectionhead#1
macro, add:\ifnum\value{linenumber}=1\thispagestyle{y}\else\fi
. Lastly, \renewcommand\linenumberfont{\color{white}} to hide line#s. :)\headsep
will shift the whole text block down.\textheight
by an equal amount within the new pagestyle. Keeping it in afancypagestyle
and using\thispagestyle
should ensure that both changes are only applied to the single page where the condition of the first line being a section heading is met.