3

I am new to LaTeX, so I was probably quite naive to think that I will get a ready answer to this but to my surprise was not able to find an answer to this.

I just want to refer to a particular line of a particular page. So that I can say "see line 2 on Page 56" and it will automatically change when the document changes.

Any suggestions will be highly appreciated!

  • You can do some simple things: make new counter, increment in every line (\everycr{\stepcounter{counter}}), set it to zero every page. But you can meet another problem: you won't be able to label other objects. – Eddy_Em Aug 31 '13 at 14:12
5

Not sure if there are any hidden caveats here, but you could use the lineno package for this. I've borrowed and modified the MWE from egreg's answer to Reference the line number in which a (new) word occurred for the first time

lineno lets you start the line numbering from 1 at each page by using \pagewiselinenumbers. I assume you don't want to display the numbers themselves, so I hid them by changing their colour to white.

Note that \pagewiselinenumbers require at least two compilation runs.

\documentclass[a4paper]{article}
\usepackage{xcolor}
\usepackage{lineno}
\pagewiselinenumbers
\renewcommand\linenumberfont{\color{white}}
\begin{document}
In the traffic court of a large mid-western city, a young
lady was brought before the judge to answer a ticket given
her for driving through a red light. She explained to his
honor that she was a school teacher and requested an immediate
disposal\linelabel{disposal} of her case in order that she might hasten
on to her classes. A wild gleam came into the judge's eye.
"You are a school teacher, eh?" said he. "Madam, I shall
realize my lifelong ambition. Sit down at that table and
write 'I went through a red light' five hundred times."


Line \ref{disposal} on page \pageref{disposal}.

Line \ref{thing} on page \pageref{thing}.

\newpage

In the traffic court of a large mid-western city, a young
lady was brought before the judge to answer a ticket given
her for\linelabel{thing} driving through a red light. She explained to his
honor that she was a school teacher and requested an immediate
disposal of her case in order that she might hasten
on to her classes. A wild gleam came into the judge's eye.
"You are a school teacher, eh?" said he. "Madam, I shall
realize my lifelong ambition. Sit down at that table and
write 'I went through a red light' five hundred times."


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.