Cross-Reference to a Line Number

Written by Allen Wyatt (last updated July 27, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


3

Peter has line numbers turned on in a document. He would like to insert a cross-reference to a specific line number, like he can insert cross-references to page numbers. It seems strange to Peter that Word can include line numbers but doesn't provide a way to reference those line numbers in a cross-reference.

Word does not allow you to create cross-references to line numbers, as Peter has already determined. The reason for this is that line numbers are considered temporary or transitory in Word. In other words, as you add text to a document, then the line numbers will change as the text is reflowed in your document. Microsoft believes—rightly so, I should note—that cross-references should be to content, not to dynamic line numbers to that content.

As an example, let's say that you have a document that includes a set of instructions. When you display line numbers, the first line of those instructions is at line number 127. As you add more text before the instructions, the first line moves to 128, 129, and finally to 133. However, you don't want your cross-reference to point to the original line number (127); you want it to point to the content that used to be at line 127 and is now at line 133.

Recognizing that cross-references should be to content and not to dynamic line numbers, Microsoft allows you to create bookmarks (to "mark" the content) and then cross-reference the bookmark. That way, as the location of the content changes, the cross-reference will always tie to that content. Here's a quick rundown of how you would create the bookmark and cross-reference:

  1. Select the text you want to be cross-referenced.
  2. Assign this text a bookmark name. (Click the Bookmark tool on the Insert tab of the ribbon. Make sure the bookmark name has no spaces in it.)
  3. Position the insertion point where you want the cross-reference to appear.
  4. Press Ctrl+F9 to insert field brackets. Make sure the insertion point stays between the brackets.
  5. Type ref followed by the name of the bookmark used in step 2.
  6. Type a space and then \h. This ensures that the cross-reference is a hyperlink to the location of the bookmark.
  7. Press F9 to update the field information. Word replaces the field with the text to which the bookmark was assigned.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13933) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting Footnotes Using Custom Footnote Marks

Automatic footnotes are easy to insert in Word documents. The default settings are usually fine for most projects. ...

Discover More

Using the Discussion Pane

Tips for using the Discussion pane during a Discussion session.

Discover More

Copying Files or Folders

A common operation within Windows is to copy files and folders from one location to another. Here are the two major ways ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Auto Creation of an Acronym List

If you use a lot of acronyms in your documents, you may want a quick way to compile those acronyms and their definitions ...

Discover More

Word Counts for a Group of Documents

Getting a word count for a single document is easy. Getting an aggregate word count for a large number of documents can ...

Discover More

Word Count is Zero

If you use the Word Count tool and are surprised that it returns a count of 0, it could be because of what you selected ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 0?

2024-07-29 14:16:30

Timothy J. McGowan

As a court reporter, generating line-numbered transcripts, I can absolutely see a need for this feature. In Minnesota, I don't need to create a table of contents that includes the line number with the page number, but I'd be surprised if there were no jurisdiction that required the marking, offering, and ruling on an exhibit, for instance, to require both page and line number.

To that end, I expect a macro would be required, to be run when all editing of the document is complete. I don't have the time, and perhaps not all the skills, required to write that macro, but generally, the problem could be solved by bookmarking everything that needs to be referenced by page and line number. Then your macro would step through and note the relative height of each bookmark on each page; it would then translate the measurement into a line number. It would require an inflexible top margin and font point size and a preprogrammed lookup table of the height of each numbered line.

Peter, if you're reading this, you may reach out to me directly, if you like, and perhaps we can figure something out for you.

Timothy J. McGowan
Court reporter
Mankato, Minnesota, USA


2024-07-27 15:15:44

Ron S

One observation on Allen's comments.

Interpreting "transitory" as changing, you can put a bookmark on a "transitory" content, for example the file name. Inserting the field code for filename, bookmark it, and insert a cross reference on bookmark works. You may have to select the cross reference and <F9> it to update as required.

NOTE: when defining the bookmark, make the name descriptive so you can easily pick out the right one from a list in the dialog.

The problem with line numbers is that they are even more changeable than field codes. The line numbers are defined in the User Interface, liker formatting a box around the paragraph. You set them in the UI, there is nothing in the document for you to select and bookmark to create the reference to.

I just thought of a manual work around if your job has an absolute requirement for reference to line numbers. But I would argue strongly against using it because it is very manual and it is easy to forget to update it. I understand, some jobs have a process or even regulatory requirement for that sort of line reference, but that is based on very "old school" conditions, ie documents that were created on typewriters or manual type setting printers.

The idea is:
Create a text box or table on left margin, in the header or footer (so it automatically appears on every page). Put your line numbers in it. Set the left margin of the body text so that text does not cover the line numbers.

(see Figure 1 below)

Apparently you don't have to modify the page margin:

This YouTube shows how to do it: https://www.youtube.com/watch?v=q8iPk9160H0

As I said, I would talk to whoever and explain the problem. Ask for permission to use the bookmarked cross reference to automate the update of the reference (no longer to a specific line, but to something on the specific line. Using Word's features to Automate updating the reference will help avoid errors. It is unfortunate that MS did not bother to include creating references to the line number feature, but they didn't, and certainly won't do it now.


Miguel, does this answer your question. Page Numbers are done via field codes, which can be bookmarked and cross referenced to.

Figure 1. 


2024-07-27 08:32:39

Miguel Antonio Suárez

Hi, ¿how are you?

This tip says "...line numbers are considered temporary or transitory in Word. In other words, as you add text to a document, then the line numbers will change as the text is reflowed in your document...". So, ¿what's the difference with page numbers? Page numbers changes too, when editing the content of documents; in fact, TOC updates automatically when page numbers changes.

Considering exposed reasons, It isn't so clear why user can able insert references to page numbers, but not with line numbers.

¿Any new ideas?

Greetings...


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.