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.
Asked
Active
Viewed 2.3k times
27
-
This is one of the things that's HARD - if not impossible - in LaTeX, while it probably just works in ConTeXt. – Martin Schröder Jun 10 '11 at 06:54
4 Answers
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
-
4For numbering of lines on a per-column basis, add the
columnwiseoption tolineno. – 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 --- I have no explanation for this. Page 4 of the lineno package documentation says that the
switchoption 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.logfile generated by the example. – Ian Thompson Feb 15 '15 at 12:33 -
@IanThompson
switchchanges 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}
-
2When I use use these options, the counter is reset at every column. However, I am not using one of the default LaTeX classes. – Antonio Sesto Apr 26 '17 at 09:20
-
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}

Sony
- 3,920
-
3Using
linenowith theswitchoption, you need to compile at least twice. Your solution works in a different context just as well. – Werner Nov 13 '11 at 21:15 -
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
TheChymera
- 546