[Tex/LaTex] Line numbers reset incorrectly using lineno package

line-numbering

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.

Best Answer

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.

I was unable to replicate the behaviour in your document, but I suspect that the likely cause is a section break at the very end of the page on which the numbering began to fail. This kind of problem is solved in the same way that a typical bad page break problem is solved.

  • rewrite the text so that the section appears earlier in the page or moves to the next page
  • insert a manual \clearpage to force the section onto the next page

This second option should obviously only be done at the last stages of writing the document.

Related Question