Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the lineno package to add linenumbers on my twosided document. However, I have a restriction to leave a margin of 2.5cm inner and 4cm outer margin. This has to be completely free space.

But the line numbers of the lineno package are being added into both those margins.

  1. Can I somehow specify that the linenumbers are added to the document body instead of the margin?
  2. If not, how do I set the margin of the document so that the correct amount of space is free of content?

I thought about just adding the line number width to the margin, but because the line numbers are always on the left margin on even and odd pages, I would have to alternate this additional margin for my twosided document.

Here is a minimal example:

\documentclass[12pt,twoside,ngerman]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,
    tmargin=2.5cm,
    bmargin=2.5cm,
    lmargin=4cm,
    rmargin=2.5cm,
    nomarginpar,
    showframe}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage{lineno}
\usepackage{lipsum}

\renewcommand{\linenumberfont}{\footnotesize}

\begin{document}

\linenumbers
\lipsum

\end{document}

This screenshot illustrates my problem:

margins

The orange line shows how far the 4cm / 2.5cm go, the blue line shows how they should actually be. The line numbers should be further to the right.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Redefine \makeLineNumber and give more room to the left margin:

\documentclass[12pt,twoside,ngerman]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,
    tmargin=2.5cm,
    bmargin=2.5cm,
    lmargin=5cm,
    rmargin=2.5cm,
    nomarginpar,
    headheight=14.5pt,
    heightrounded,
    showframe}
\AtBeginDocument{\addtolength{\evensidemargin}{1cm}}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage{lineno}
\usepackage{lipsum}

\renewcommand{\makeLineNumber}{\llap{\linenumberfont\rlap{\LineNumber}\hspace{1cm}}}

\renewcommand{\linenumberfont}{\footnotesize}

\begin{document}

\linenumbers

\noindent% just to make a rule
\llap{\vrule height 1pt width 3.9cm\hskip1cm}%
\lipsum[1-6]

\noindent% just to make a rule
\llap{\vrule height 1pt width 2.4cm\hskip1cm}%
\lipsum[7]

\end{document}

The two rules are just 1mm short so that we can see the measurement is accurate. I added a setting for headheight and also heightrounded; the first is required by fancyhdr, the second makes the text height contain an integer number of lines.

Top of page 1

enter image description here

Top of page 2

enter image description here

share|improve this answer
    
Hi, thanks for your help. While the left margin is correct now on both pages, the right one now is too wide. See this screenshot: oi40.tinypic.com/351a721.jpg Any idea how to fix that? –  atticae Nov 23 '13 at 20:47
    
@atticae I get 4cm on the odd pages and 2.5 on the even pages. If you want to fix also the opposite margin, just tell it to geometry. –  egreg Nov 23 '13 at 20:59
    
I also get those values on the left (not inner) margin, as its supposed to be. But the right (not outer) margin is wrong. I can't fix that via geometry because I can only change outer and inner margin, not left and right on both odd and even pages. –  atticae Nov 23 '13 at 21:06
    
@atticae Sorry, but I don't understand –  egreg Nov 23 '13 at 21:09
    
As I wrote in the question, I need the inner margin to be 4cm, the outer to be 2.5cm. Your fix helps me get the left side of each page (where line numbers are) correct, but now the right side of each page is wrong. (see the measurements on the right in the screenshot in my previous comment). –  atticae Nov 23 '13 at 21:11

but because the line numbers are always on the left margin on even and odd pages

The assumption is not true. You can use the switch option of the lineno package. See Line numbers on different margins in two-sided document for a MWE.

share|improve this answer
    
I am aware of that. I actually want them to be always on the left side. By "always" I was just referring to my document. –  atticae Nov 24 '13 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.