27

How to add line number to a 2 column document where the line number must appear on the left for the left column and on the right for the right column. The lineno package does not seem to provide this option.

lockstep
  • 250,273
suresh
  • 1,447

4 Answers4

33

Use the switch option for the lineno package.

\documentclass[twocolumn]{article}
\usepackage[switch]{lineno} 
\usepackage{lipsum} %Creates example text
\begin{document}
\linenumbers
\lipsum[1-20]
\end{document}
Ian Thompson
  • 43,767
  • 3
    The line numbers appear on the right of the left column in this answer. – Sony Nov 12 '11 at 01:04
  • 4
    For numbering of lines on a per-column basis, add the columnwise option to lineno. – Werner Nov 13 '11 at 21:16
  • 9
    @Sony --- Not so on my machine. Make sure you compile twice so that the warning about line number reference goes away. – Ian Thompson Nov 22 '11 at 16:14
  • This didn't work for me either. Neither did adding the 'columnwise' option as per @Werner – DKS Feb 13 '15 at 10:24
  • @DKS --- What TeX distribution are you using? – Ian Thompson Feb 13 '15 at 22:40
  • @IanThompson MikTeX. All latest. – DKS Feb 15 '15 at 00:51
  • @DKS --- I have no explanation for this. Page 4 of the lineno package documentation says that the switch option has this effect. It worked when I posted the answer and it works on my machine now (TeXLive 2014). Perhaps you could ask a new question about the issue, including the .log file generated by the example. – Ian Thompson Feb 15 '15 at 12:33
  • @IanThompson switch changes things pagewise, not columnwise. Submitted my Marked Up Manuscript w/o this nice thing though. Will see if I need it again in future. – DKS Feb 16 '15 at 13:02
  • @DVK --- you are right; that's the documented behaviour. Perhaps columnwise changes are an undocumented feature that works with some documents but not others. Does my example work on your machine? – Ian Thompson Feb 16 '15 at 20:07
  • switch: Sporadically does the right thing but I can't explain why. Mulitple recompiles needed to achieve the desired result? columnwise: Line numbers always to the left of the column, line numbers for right column overlap the text of the left column; Line numbers restart at 1 on the right column. Not good. columnwise,switch: both left and right columns start numbering at line 1 on each page. Not good. – MRule Apr 19 '23 at 09:06
15

Simply add [columnwise] in the options of the package:

\usepackage[switch,columnwise]{lineno}
diabonas
  • 25,784
mitch
  • 151
8

The following is a partial solution.

\documentclass{article}
\usepackage{multicol}
\usepackage{lineno} 
\usepackage{lipsum}
\begin{document}
\begin{multicols}{2}
\linenumbers
\lipsum[1-1]
\columnbreak
\rightlinenumbers
\lipsum[1-1]
\end{multicols}
\end{document}

enter image description here

Sony
  • 3,920
3

I don't know if I've just developed a fortunate hack, or if this is how the package is supposed to be used, but I also had the issue that Ian Thompson's answer did not produce running numbering but columnwise numbering.

I got outer-margin two-column running numbering with the following code:

\documentclass[twocolumn]{article}
\usepackage[switch]{lineno} 
\usepackage{lipsum} %Creates example text
\begin{document}
\runningpagewiselinenumbers
\linenumbers
\lipsum[1-20]
\end{document}

Note that this needs to be compiled twice for the line numbering to be displayed correctly:

pdflatex docname.tex
pdflatex docname.tex