103

How can I cite a range of papers, the output is a range of numbers, instead of a list of numbers? In other words, when I type

... some dummy text here is due to me \cite{me1, me2, me3, me4} ...

I want the output to be

... some dummy text here is due to me [3-6] ...

instead of

... some dummy text here is due to me [3.4.5.6] ...

(I use LaTeX, and am currently using the amsart class and whatever it includes. But I am open to other suggestions.)

Jonas Stein
  • 8,909
Willie Wong
  • 24,733
  • 8
  • 74
  • 106

3 Answers3

95

The cite, natbib, and biblatex packages, at least, will all do this.


A minimal example which demonstrates the behaviour is:

\documentclass{article}
\begin{document}
hello \cite{article-full,book-full,mastersthesis-full}
\bibliographystyle{unsrt}
\bibliography{xampl}
\end{document}

If you have basic bibliography needs, adding \usepackage{cite} will produce the desired behaviour.

If you have more complex bibliography needs, nowadays I recommend biblatex as a first choice, although natbib has a long and distinguished history in this space and is possibly a better option if you want a more ‘stable’ solution.

For biblatex, you would now write this example as:

\documentclass{article}
\usepackage[style=numeric-comp]{biblatex}
\bibliography{xampl}
\begin{document}
hello \cite{article-full,book-full,mastersthesis-full}
\printbibliography
\end{document}

Noting that you need to process the bibliography using biber instead of bibtex. (You can use bibtex by adding backend=bibtex to the package options, but I'm not sure if that is currently recommended for new documents.)

If you are using natbib, a minimal example would be:

\documentclass{article}
\usepackage[numbers,sort&compress]{natbib}
\begin{document}
hello \citep{article-full,booklet-full,mastersthesis-full}
\bibliographystyle{unsrtnat}
\bibliography{xampl}
\end{document}
  • 4
    Ah, the cite package. That gives a minimal work solution to my problem. Thanks. – Willie Wong Oct 07 '10 at 15:50
  • 1
    (I also realized that the amsrefs package can do it, but I didn't feel like retyping 92 citation entries.) – Willie Wong Oct 07 '10 at 15:52
  • warning -- biblatex hasn't been tested with amsart, and i can't predict whether it will work; i'm inclined to think it may not be totally smooth sailing. – barbara beeton Dec 30 '11 at 21:32
  • Hi will, is there any chance of expanding the answer? This seems to be high up on google, but it is a bit unspecific. Just as the question :-( – Johannes_B Aug 27 '17 at 09:45
  • @Johannes_B — thanks for noticing; what do you think of the new text? – Will Robertson Aug 27 '17 at 11:51
  • Apparently natbib does not like the {} directly in front of years. Apart from that, good update. It will be more helpful in the future. By the way, i started to rewrite parts of the wikibook -> https://en.wikibooks.org/wiki/LaTeX/Creating_a_Bibliography – Johannes_B Aug 27 '17 at 12:02
  • @Johannes_B Hmmmf. Thanks for looking into it. – Will Robertson Aug 29 '17 at 00:00
  • natbib produces a good number of error messages like Missing } inserted. and Extra }, or forgotten \endgroup., same for biber, both exporting bibtex and biblatex with Zotero. Am I doing something obviously wrong? – Trylks Mar 04 '21 at 11:34
52

if you add

\usepackage[numbers,sort&compress]{natbib}

to your preamble, you should get the expected result.

Habi
  • 7,694
  • one question! In the case of the 'cite' package, it ok to use: '\usepackage[numbers,sort&compress]{cite}' – Josh Jun 23 '13 at 14:31
  • 2
    If I test it, I see that \usepackage[square,numbers,sort&compress]{natbib} seems to be the same as \usepackage{cite} if using the plain bibliography style. The options of the cite package can be found in its documentation (numbers isn't one of them...). – Habi Jun 24 '13 at 15:06
36

Using biblatex, sorting and compressing numeric keys is achieved with

\usepackage[style=numeric-comp]{biblatex}
Werner
  • 603,163
lockstep
  • 250,273
  • Can confirm that it works for LyX Version 2.3.6.1, by using as configs: Tools -> Preferences -> Output -> LaTeX -> processor=biber and in Document -> Settings -> Bibliography I've put citation style = numeric-comp and bibliography style = ieee, but this latter one won't matter, I'm just being thorough about something that behaves as expected for my use case, which was appearence order and the citing range [as wanted by OP] – daydreamer Jul 13 '21 at 00:13