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.

I have a need to make the build crash when a \section takes more than a single page (in a given environment). How can I achieve that?

share|improve this question
Is "a section" now some range in an environment or a \section? –  Martin Scharrer Apr 18 '11 at 7:57
The 'sections' tag you added is the plural version of 'section' which is already an synonym of 'sectioning'. According with the tagging rules applied to this site I made it as well a synonym of 'sectioning'. That tag is for all sectioning macros like \chapter, \section, \subsection, etc. Feel free to remove it if its doesn't fit for your question. Sorry for the hassle. –  Martin Scharrer Apr 18 '11 at 8:06
Thanks for the comments. I'm talking about \section indeed. –  ℝaphink Apr 18 '11 at 8:08

1 Answer 1

up vote 1 down vote accepted

You could add a label after the \section and after the end of it and then compare the pagenumbers e.g. using the macro \vrefpagenum of the varioref package. IMHO this is saver then using \pageref directly because it could include other material like hyperlinks, but I might be wrong.




        \GenericError{}{Section longer than one page!}{}{}%


   \section{Some section}\label{sec:some}       


   \section{Other section}\label{sec:other}
   % Alternative:


You could also make an environment which places this labels at the \begin and \end and runs the check automatically. I might need to use \refstepcounter{dummy} (where dummy is some dummy counter) to make the \label produce the correct page number.

A problem with this solutions is that there might be error caused because of an outdated .aux file.

share|improve this answer
Interesting solution. Ideally though, I'd like to make it so that I don't have to add a tab at the end of each section. Also, wouldn't it be easier to just set a counter to \thepage at the beginning of the section and compare with \thepage at the end of the section? –  ℝaphink Apr 18 '11 at 8:36
@Raphink: No, the \thepage macro is not reliable (except in footers and headers), because when it is processed the page is not yet fully build and TeX doesn't know if the material it is used in is part of the current page or not. –  Martin Scharrer Apr 18 '11 at 8:49
@Martin: even if I build several times (I'm used to building 3 times to make sure references are fine after everything is positioned)? I'm using \thepage in a \titleformat{\section} command to display tabs on the side of the page, and I've had no problems with it. Is that a mistake? –  ℝaphink Apr 18 '11 at 8:53
@Raphink: Yes, \thepage simply adds the number of the page counter which is unaffected by reruns. Using \thepage might get you the correct number but it is not guaranteed. –  Martin Scharrer Apr 18 '11 at 8:58
@Martin: I plan on adding this check system to \titleformat because I need to check all sections. Using labels, I will end up with labels titled the same in all sections... –  ℝaphink Apr 18 '11 at 9:06

Your Answer


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.