16

Is there a possibility to get (in an onecolumn article) line numbers on both sides (left and right) displayed? I used the lineno-package for a one-sided numeration, but I fail to use it for left and right simultaneously.

\documentclass{article}
\usepackage[left]{lineno}
\usepackage{blindtext}

\begin{document}
\linenumbers
\blindtext
\end{document}
phymics
  • 163
  • 1
  • 1
  • 5

3 Answers3

14

You could update the way the left (default) option works. That is, update \makeLineNumbersLeft and re-issue \leftlinenumbers:

enter image description here

\documentclass{article}
\usepackage{lineno}

\makeatletter
\def\makeLineNumberLeft{%
  \linenumberfont\llap{\hb@xt@\linenumberwidth{\LineNumber\hss}\hskip\linenumbersep}% left line number
  \hskip\columnwidth% skip over column of text
  \rlap{\hskip\linenumbersep\hb@xt@\linenumberwidth{\hss\LineNumber}}\hss}% right line number
\leftlinenumbers% Re-issue [left] option
\makeatother

\usepackage{blindtext}

\begin{document}
\linenumbers

\blindtext
\end{document}
Werner
  • 603,163
4

This approach will not work across page boundaries (which is why I upvoted Werner's answer). But since I did it, I'll present it. I set up \lrlineno[start no]{text}.

Basically, I print it out in white, with left line numbers, then do a \vspace to the beginning of the block, and reprint it out in black, using right line numbers.

\documentclass{article}
\usepackage[left]{lineno}
\usepackage{xcolor}
\usepackage{blindtext}
\newlength\tmplen
\newcommand\lrlineno[2][1]{%
\linenumbers%
\setcounter{linenumber}{#1}%
\leftlinenumbers%
\color{white}#2\color{black}%
\par%
\setcounter{linenumber}{#1}%
\setbox0=\vbox{#2}%
\setlength\tmplen{\dimexpr\dp0+\ht0+\the\dp\strutbox}%
\vspace*{-\tmplen}%
\rightlinenumbers%
#2%
\par%
\nolinenumbers%
}
\begin{document}

Testing left-right line numbers, beginning at 3

\lrlineno[3]{\blindtext}

Test is complete.
\end{document}

enter image description here

2

Solution

Well, by default the standard classes: article, letter and report use the option oneside meanwhile book uses twoside. We need to add that option in the class before. If you want numbers in both margins you can use switch instead of left in your document.

\documentclass[twoside]{article}
\usepackage[switch]{lineno}
\usepackage{blindtext}
\usepackage{lipsum}

\begin{document}
\linenumbers
\blindtext

\section{First Attempt}
\lipsum

\section{Another stuff}
\lipsum

\end{document}

You don't need to do something more complicated. The package lineno is able to do what you want. Try the code above and see. If you want to get numbers in bot margins in the same page, would be able, but check the package documentation for that.

Aradnix
  • 3,735
  • 2
  • 20
  • 43
  • According to the manual, "Margin switching is independent of any [twoside] option of the document class." I get the margin switching (page by page) just by specifying [switch] without [twoside]. – GuiltyDolphin Jun 02 '20 at 10:38