[Tex/LaTex] How to add paragraph line number in right margin


In passages, the line numbers are given on the right side of the paragraph. Like this:
enter image description here

How could this be implemented in LaTeX?

Best Answer

The lineno package is what you are looking for.

As a first approximation to what you want: \usepackage[modulo,right]{lineno}. If you want the numbers to start from 1 on every page, add the option pagewise. Unfortunately, the package isn't perfect and will go a little... odd when there's a lot of mathmode or figures.

You then need to activate it with \linenumbers. Personally, I prefer to use line numbers only in draft mode. So with the ifdraft package, I write \ifdraft{\linenumbers}{} so that when I'm not compiling drafts, I don't see the ugly numbers.

If you want line numbers inside a framed box, for example, you need to put \internallinenumbers at the beginning of the environment. I just checked this works with mdframed...

Here is some example code:

\usepackage{lipsum} % The lipsum package is only used to generate dummy text

The documentation is available here.

Related Question