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, andcolorpackages, so it is not an elegant solution by any means. First initiatelinenoto insert line numbers to your document;linenoadds a counter calledlinenumberwhich you can reset for every new page by adding \@addtoreset{linenumber}{page}. – John Jan 16 '12 at 20:16fancypagestyle{y}that adds the x shift\setlength{\headsep}{x}Then, when you define your\def\@makesectionhead#1macro, add:\ifnum\value{linenumber}=1\thispagestyle{y}\else\fi. Lastly, \renewcommand\linenumberfont{\color{white}} to hide line#s. :) – John Jan 16 '12 at 20:27\headsepwill shift the whole text block down. – egreg Jan 16 '12 at 21:15\textheightby an equal amount within the new pagestyle. Keeping it in afancypagestyleand using\thispagestyleshould ensure that both changes are only applied to the single page where the condition of the first line being a section heading is met. – John Jan 17 '12 at 7:46