## Sunday, July 29, 2007

### Sort and compress numerical citations

As mentioned in Latex hyperref and cite packages, packages cite and natbib are used to sort numerical citations. The usage of cite is

\usepackage{cite}

It is quite simple because you don't need to do anything more. [21,18,22,23] will be automatically sorted and compressed as [18, 21-23].

To get the same results, options needed to be provided using natbib:

\usepackage[options]{natbib}

Options can be sort&compress or compress. The former one sorts and compresses the citations and the latter one compresses the citations only. Because of the compatible issue, natbib is recommended.

1. Thank you!!

2. Could you please give an example of how the citations are used in the tex file in order to use the above package? I have tried it with no errors but the sorting is not working properly.

3. Dear Azlin,
The usage is as follows:

\usepackage[sort&compress]{natbib}

If you have complied the tex file before you used this package, try to delete all other files that were generated during compling, and then compile it again.

4. Thank you very much. This was a useful tip.
Is there a way to tell natbib to compress [21,22] into [21-22] i.e. even if there are only two consecutive citations, I want natbib to compress it. Because it now appears as [21, 22] (with a space after the comma), which is ugly and spoils the compact look of my document. I will be happy with [21,22] or [21-22] but I have no idea how to achieve this.

5. Hi, Ramanathan,

I don't think natbib can do that. "-" is used when there are three or more references. Similar with et al., you don't use "-" between two items. But may natbib support it. Please check the package document.

6. you can always use \bibpunct{[}{]}{,\!}{n}{}{;} with negative space after the separator ',' to remove the space between 2 references

7. Thank you that worked fine!

8. I would want to have citations sorted and compressed but in separate brackets, like [3], [6]-[8]. Please let me know if that is possible with natlib.