2

I've made this code to number paragraphs for easy reference, but if a paragraph "normally starts" in a new page that paragraph number goes out of the scope of the page. The numbering works fine if a \clearpage or \linebreak is issued before.

Please note that the 7th paragraph does not show up on the margin, while all the others are fine:

\documentclass[a4paper,12pt,twoside]{report} 
\usepackage[width=159.2mm,top=25.4mm,bottom=25.4mm]{geometry} 
%I'm using width to make room for the binding of the thesis and still keeping the 25.4mm for the side margins
\usepackage{lipsum}

% % Set Numbering to Paragraphs % %
%\reversemarginpar %Use this to keep \marginpar in left margin
\newcounter{parnum}
\newcommand{\n}{%
\leavevmode\refstepcounter{parnum}%
\ifodd\value{page} %For twosided pages until \fi
     \marginpar{\makebox[\marginparwidth][l]{\scriptsize{\textsection\theparnum}}}
\else
     \marginpar{\makebox[\marginparwidth][r]{\scriptsize{\textsection\theparnum}}}
\fi}

\begin{document}
\n\lipsum[1]
\n\lipsum[2]
\n\lipsum[3]
\n\lipsum[4]
\n\lipsum[5]
\n\lipsum[6]
\n\lipsum[7]
\n\lipsum[8]
\n\lipsum[9]
\n\lipsum[10]
\end{document}

Is it a bug, or am I doing something wrong? Thanks for your help and attention!

1 Answer 1

3

In your layout the margin notes are wider that the outer margin. First of all, if you make custom margins, play with \marginparwidth and \marginparsep lengths to find a suitable layout for your notes in these margins (the package layout can help a lot in this testing steps).

On the other hand, \ifodd\value is useless here because \marginpar already take care of the odd/even page in a twoside report. Moreover, this way note that §7 is not printed by the \else ... part of your macro but by the first part (i.e., when is evaluated, \lipsum[7] is still in the first page) and thus is left aligned, but because \marginparwidth is too long, the counter is printed out of the paper.

Therefore your macro can be simplified without conditionals, and with a single \marginpar and without any \makebox inside, even when if notes for odd and even pages are not the same, as show this example:

mew

\documentclass[a4paper,12pt,twoside]{report} 
\usepackage[width=159.2mm,top=25.4mm,bottom=25.4mm]{geometry} 
\usepackage{lipsum}
\marginparwidth=30pt\marginparsep=20pt
\newcounter{parnum}
\newcommand{\n}{\refstepcounter{parnum}\leavevmode%
\marginpar[\theparnum\S\hfill]{\hfill\S\theparnum}}
\begin{document}
\n\lipsum[1]
\n\lipsum[2]
\n\lipsum[3]
\n\lipsum[4]
\n\lipsum[5]
\n\lipsum[6]
\n\lipsum[7]
\n\lipsum[8]
\n\lipsum[9]
\n\lipsum[10]
\end{document}
2
  • Sorry, the \textsectiontheparnum missed a back slash \textsection\theparnum while I was setting it in the question, fixed now! I was using makebox because all numbering in the left were out of scope. Your code works just perfect! Thanks for the help!
    – hehe_br
    Sep 25, 2015 at 9:04
  • @hehe_br You are welcome. A good rule to avoid typos int the question and answers is make the images compiling the code pasted in TeX.SX, not the code already written in your LaTeX editor. (I also should remind of not to forget this). ;)
    – Fran
    Sep 25, 2015 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .