# Line numbers reset incorrectly using lineno package

Having a strange problem using lineno.

The document I'm creating is a 24-page legal document. I'm numbering all the lines using lineno for easy reference. The line numbers need to be reset every page and it all works perfectly until page 17. From page 18 on, instead of line '1' being on the top of the page, it appears as the last line of the previous page.

The only relevant code I can see are both in the preamble:

\usepackage{lineno}
....
....
....
\pagewiselinenumbers
....
\begin{document}


Problem with this question is I understand it may be hard to answer. I'm hoping someone else has had similar problems that they found the solution to.

• What document class are you using? – Alan Munn Aug 9 '11 at 21:54
• Anything special about pages 17/18? Perhaps inclusion of a figure? A special environment that you used? (Re)Newcommands and the like? How about page 19? Does it start numbering properly with 1 again? Remember, for \pagewiselinenumbers to work, you have to compile the document at least twice. – Werner Aug 9 '11 at 22:24
• In addition to @Werner's good suggestions, is there a section heading right at the end of p. 17? If you add a few lines more of text at page 17 does the problem still arise? – Alan Munn Aug 9 '11 at 22:48
• @Alan I'm using article. Werner There is no new environment on either of those pages. The only time I introduce a new environment is on page 23 where I introduce an enumerate environment. From 18-24, all the lines begin on number 2, with 1 acting as the final line of the previous page. NOW, Alan, that is exactly it. It began a new section (I use a command I call \xsection) right at the bottom of page 17. Adding some dummy text there completely fixed the problem. Do you know why it does this? – Robert Ray Aug 9 '11 at 23:32
• Well I can't reproduce the problem, but it seemed like a reasonable guess. And I suspect the system can never be foolproof, so I think the best you can do is rework your text a little to fix the bad break. (Or issue a \clearpage right before this particular \xsection so that it begins on the next page.) – Alan Munn Aug 10 '11 at 0:05

The lineno package does a remarkable job of adding numbers to the text, but there are various ways in which it might get it wrong, not through any real deficiency in the package, but just due to the complexities of how pages are built in TeX.
The pagewise numbering scheme requires the package to write the line numbers first to an .aux file, which it then reads back on a second run to generate the per-page numbers.
• insert a manual \clearpage to force the section onto the next page