3

I want to refer to line numbers in code which I have in my appendix. Each piece of code is in its own section where line numbers begin from 1.

I want to be able to write something like;

"With reference to line 23 in code snippet 6.8, ..."

If I add or remove lines above the text being referenced or if I change the margins or font size such that wrapping causes lines to be created or destroyed, then I want the line number reference to update just like a numbered item reference would update if the chapter numbers change.

What I've tried so far:

  1. I checked in the cross-references section of Word 2013 but wasn't able to find a line number reference type. Can I create such a reference type?
  2. I tried simply selecting the entire code section and turning it into a numbered list, which I could then reference, but that bungles on line wrapping and indented code. Also it would be a bit of work setting up the styles and it would be much cleaner to use Word's built-in line numbering tool.
3

Unfortunately word doesn't have a way to generate cross-references to line numbers. You might have some luck creating a complex VBA macro that would satisfy this requirement, but most likely a better idea is to just rethink how you want to display your cross-references.

| improve this answer | |

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.