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 trying to implement paragraph numbering with memoir. I would like the numbers to be

  1. in the outside margin,
  2. flush against the text block, and
  3. vertically aligned with the first line of the paragraph.

Combining various bits of code I found here at Stack Exchange, I have

\documentclass[12pt]{memoir}
\pagestyle{empty}

\usepackage{lipsum}

\strictpagecheck
\newcounter{PN}
\marginparmargin{outer}

%% ATTEMPT A
\newcommand{\pnum}{\addtocounter{PN}{1}\marginpar{\mpjustification\arabic{PN}}}

%% ATTEMPT B
%\newcommand{\pnum}{\addtocounter{PN}{1}\hspace{0pt}\marginpar{\mpjustification\arabic{PN}}}

\begin{document}

\pnum\lipsum[\value{PN}]

\pnum\lipsum[\value{PN}]

\end{document}

Both attempt A and attempt B are close. But A puts the numbers too high, so that they are between the last line of the previous paragraph and the first line of the current paragraph, while B puts the numbers too low, so that they are between the first and second lines of the current paragraph.

Any suggestions would be appreciated.

EDIT: My Response to the Responses

The suggestions from both Mike Renfro and Gonzalo Medina were helpful (and I flagged them as such). In my actual document, I change the style of the chapter titles, and this for some reason causes the paragraph numbers to be shifted on the first page of each chapter. (If I do not apply the custom chapter style, this issue goes away.) I ultimately chose Mike's answer because it doesn't have this issue. Thanks to both of you (and lockstep). Also, I didn't know about the \stepcounter command; that's more elegant.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Working from Gonzalo's answer, but using memoir's built-in marginal note capabilities (see section 12.3 of the memoir manual):

\documentclass[12pt]{memoir}
\pagestyle{empty}
\usepackage{lipsum}   
\newcounter{PN}
\sideparmargin{outer}   
\newcommand\pnum{%
  \stepcounter{PN}\sidepar{\arabic{PN}}}
\begin{document}
\pnum\lipsum[\value{PN}]
\pnum\lipsum[\value{PN}]
\end{document}
share|improve this answer
add comment

Perhaps using \marginnote from the marginnote package?

\documentclass[12pt]{memoir}
\pagestyle{empty}
\usepackage{marginnote}
\usepackage{lipsum}

\strictpagecheck
\newcounter{PN}
\marginparmargin{outer}

\newcommand\pnum{%
  \stepcounter{PN}\marginnote{\mpjustification\arabic{PN}}}

\begin{document}

\pnum\lipsum[\value{PN}]

\pnum\lipsum[\value{PN}]

\end{document}

enter image description here

If you want something automatic (up to certain extent) you can use \everypar:

\documentclass[12pt]{memoir}
\usepackage{lipsum}

\newcounter{PN}
\marginparmargin{outer}

\reversemarginpar

\newcommand\countpar{%
    \everypar{\stepcounter{PN}\marginpar{\arabic{PN}}}%
}
\newcommand\mcountpar{%
    \stepcounter{PN}\marginpar{\arabic{PN}}%
}

\pagestyle{empty}

\begin{document}
\countpar
\lipsum[1-2]

\begin{enumerate}
\item \mbox{}\mcountpar\lipsum[2]
\end{enumerate}

\end{document}

\stepcounter{PN} could be changed to \refstepcounter{PN} if one wants to cross-reference paragraphs (Thanks to lockstep for pointing out this).

share|improve this answer
add comment

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.