7

I am drawing up a document that has numbered paragraphs. 1-36 are numbered normally and I have no problems. However, on paragraph 37, I need something like:

35 Normal paragraph.

36 Normal paragraph.

37-46 The following paragraphs correspond to text text text text, text text.

47 Normal paragraph.

I'm numbering my paragraphs using:

\newcounter{xpar}
\setcounter{xpar}{1}
\newcommand{\xp}{\arabic{xpar}\stepcounter{xpar}.\hspace{.5in}}

Can anyone help me figure out how to number the paragraph with a 37-46, and then continue on with 47?

2
  • 3
    Your code contains some errors: instead of \setcounter{xpar}, you should use \setcounter{xpar}{1} (or another value) or \stepcounter{xpar}, and instead of \newcommand{xp}{...} you should use \newcommand{\xp}{...}. Aug 4, 2011 at 21:44
  • Good catch; I already had those corrections...just typed this in here too quickly. Bad form on my part. Thanks, though.
    – Robert Ray
    Aug 4, 2011 at 21:47

1 Answer 1

8

Add an optional argument for the "number of additional paragraphs" to the definition of your \xp macro. If the optional argument is empty, typeset the paragraph label as usual. If not, increase your custom counter as appropriate and also typeset the (new) label.

\documentclass{article}

\newcounter{xpar}
\newcommand{\xp}[1][]{%
  \stepcounter{xpar}%
  \arabic{xpar}%
  \ifx #1\empty
  \else
    \addtocounter{xpar}{#1}%
    --\arabic{xpar}%
  \fi
  .\hspace{.5in}\ignorespaces
}

\begin{document}

\xp Some text.

\xp[3] Some text.

\xp Some text.

\end{document} 
5
  • I think adding #1-1 is a bit more intuitive.
    – Caramdir
    Aug 4, 2011 at 21:47
  • 1
    I like this solution better, so I will delete mine. Aug 4, 2011 at 21:49
  • 2
    Just a suggestion: you could add something like \newlength\mylen before the definition of \xp, and change the \else part to \else \addtocounter{xpar}{#1}\settowidth\mylen{--\arabic{xpar}}% --\arabic{xpar}\hspace{-\mylen}% so that all the paragraphs would have the same indentation. Aug 4, 2011 at 22:01
  • This solution worked perfectly.
    – Robert Ray
    Aug 4, 2011 at 22:03
  • @Robert: Thanks! Don't forget to accept my answer after some time if no better one comes along. :-)
    – lockstep
    Aug 4, 2011 at 22:10

You must log in to answer this question.

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