Cross references in Latex allow me to print the page number of a reference. How can I print the line number too (for instance the word Lily appears on page xxx, line xx)? Thank you, A
Asked
Active
Viewed 642 times
1 Answers
5
Following up on @Werner's suggestion, you may want to use the lineno ("line numbers") package. Load it with the option pagewise, turn line numbering on with the instruction \linenumbers, insert \linelabel{<somelabelstring>} next to the word whose line number you're interested in, and use \ref{<somelabelstring>} and \pageref{<somelabelstring>} elsewhere to create cross-references that list the line number and associated page number.
For instance, the following code
\documentclass[letterpaper]{article}
\usepackage[pagewise]{lineno}
\usepackage{lipsum}
\begin{document}
\linenumbers % enable line numbering
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque\linelabel{word:pellentesque} habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
\newpage
\nolinenumbers % disable line numbering
The word \emph{pellentesque} occurs on line \ref{word:pellentesque} of page~\pageref{word:pellentesque}.
\end{document}
generates the following output (on page 2), after running LaTeX twice:
The word pellentesque occurs on line 4 of page 1.
Mico
- 506,678
-
Thanks Werner and Mico, this method works. I found a workaround by setting \modulolinenumbers to a very high value, so the line numbers is not shown. – user56153 Jan 27 '15 at 22:07
-
1@user56153 - Indeed, executing
\modulolinenumbers[<some large integer value>]will succeed in not showing the line numbers, though at the cost of not making it easy for your readers to find the line in question... – Mico Jan 27 '15 at 22:10 -
1In my case this is exactly what I needed: my project is more on the reading than on the reference side. – user56153 Jan 27 '15 at 22:13
-
1
linenopackage, but it has its limitations. – Werner Jan 27 '15 at 19:04