Natbib is a reimplementation of the \cite command, providing both, author-year and numerical citations.You can get the distribution as well as the documentation from CTAN.Apparently, my previous post on this topic was not providing sufficient information in order to automatically create lists for multiple citations, e.g. [1,2,3, 5] -> [1-3, 5].Here is how it definitely works using “natbib”: First you include the package into your document with whatever options you prefer:
\usepackage[square, comma, sort&compress]{natbib}
Here, “sort&compress” provides the effect we are looking for, i.e. comma separation and hyphenation of multiple citations. By default, natbib uses round parentheses and colons, hence I changed them to square brackets and commas.Use
\citet{wikiEn}
for textual and
\citep{wikiEn}
for parenthetical citation, instead of \cite. The following example shows how Natbib replaces more than two consecutive citations by a hypen:
\documentclass{article} \usepackage[square, comma, sort&compress]{natbib} \begin{document} \section{Comma separated citations} Most popular search engines include Google and Yahoo, \citep{google, yahoo}. \section{Citation list} The most popular free online encyclopaedia is available in different languages, \citep{wikiEn, wikiDe, wikiFr}. \bibliographystyle{plainnat} \begin{thebibliography}{99} \bibitem{google}http://www.google.com. Google Inc. search engine, 2008. \bibitem{yahoo}http://www.yahoo.com. Yahoo! Inc. search engine, 2008. \bibitem{wikiEn}http://en.wikipedia.org. Wikipedia in English, 2008. \bibitem{wikiDe}http://de.wikipedia.org. Wikipedia in German, 2008. \bibitem{wikiFr}http://fr.wikipedia.org. Wikipedia in French, 2008. \end{thebibliography} \end{document}
My apologies, I got something wrong here in the first place. Natbib is not a bibliography-style, but a package providing author-year and numerical citation. Natbib is supported by the following three styles:
plainnat.bst, abbrvnat.bst and unsrtnat.bst
which replace the standard bst-files.
(Source: http://merkel.zoneo.net/Latex/natbib.php)
Update
The code above doesn’t seem to work any longer. Here is the same code where natbib was replaced by cite (package documentation):
\documentclass{article} \usepackage{cite} \begin{document} \section{Comma separated citations} Most popular search engines include Google and Yahoo, \cite{google, yahoo}. \section{Citation list} The most popular free online encyclopaedia is available in different languages, \cite{google, wikiEn, wikiDe, wikiFr}. \bibliographystyle{plainnat} \begin{thebibliography}{99} \bibitem{google}http://www.google.com. Google Inc. search engine, 2008. \bibitem{yahoo}http://www.yahoo.com. Yahoo! Inc. search engine, 2008. \bibitem{wikiEn}http://en.wikipedia.org. Wikipedia in English, 2008. \bibitem{wikiDe}http://de.wikipedia.org. Wikipedia in German, 2008. \bibitem{wikiFr}http://fr.wikipedia.org. Wikipedia in French, 2008. \end{thebibliography} \end{document}
satsuma
Thanks for the good info, this really helps. One thing that your posting does not cover though, and neither does any other site that I’ve found about natbib, is how to set page numbers for multiple citations.
What I mean is that sometimes it’s needed to have the citation like this: [2, p. 15 ; 4, p 181]
I am not experienced enough with LaTex to provide a work-around for this. If you have a clue on how to do this, please add it to your blog. Appreciate it. Thanks.
tom
Hi!
You are right, natbib cannot do it. But you can define your own citation-command as a work-around:
And now you can have multiple citations with page numbers as follows:
satsuma
For some reason in my environment the natbib didn’t seem to have a command \citenum. All I got was an undefined control sequence error. But when I downloaded the natbib.sty and included in the directory where my tex files are, it is working.
Thanks for sharing that work-around.
satsuma
The problem with \citenum problem is that the version of natbib that came with LaTex is an old version from 2003. The new one I downloaded is from 2007.
Louic
Thanks for your website, it’s very informative.
I needed to download hypernat.sty and use
to get the
sort&compress
to work.Apparently there is a conflict between hyperref and natbib, which is solved by using hypernat.
Happy TeX’ing
JRM
it actually works
k
I had to spend an hour with Google to find this one trivial command:
which puts a citation in your
\bibliography
, without showing up in the actual text (good for abstracts)Pradeep
Thanks a lot buddy.. How to use “square brackets” in natbib trick worked….
Eivind Uggedal
satsuma: In my own thesis class I have to following to cite two sources with pages:
sohail
Using natbib, for a single citation with page number and the text see e.g. I do
and it generates
(see e.g. Efron and Tibshirani, 1993, p.394)
but I am unable to do the same for the multiple citation with page numbers and the text see e.g. like
(see e.g. Efron and Tibshirani, 1993, p.107; Chernick, 1999, p.84)
Naveen
Thanks Tom!! That helped.
Courtney
Thank you Louic!
For those using natbib and hyperref, it is required to use
to allow natbib to use sort&compress properly. Finding your post saved me many hours!
kezz
Thanks very much for this!
Mander
@sohail:
I get around that kind of problem with judicious use of \citealp, \citealt, etc. For instance:
There is some evidence of seasonal distribution of goods (\citealp[9]{freddie04transition}, see also \citealt{vicent97island}), as well as a strong suggestion blah blah blah
compiles as:
There is some evidence of seasonal distribution of goods (Freddie 2004:9, see also Vicent 1997), as well as a strong suggestion blah blah blah
Rachel
Thank you for this post. I found that after adding \usepackage[square, comma, sort&compress]{natbib}, I got the error “! Package natbib Error: Bibliography not compatible with author-year citations.” After searching on another forum (http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2009-03/msg00162.html) I found that the solution is to add the option “numbers” to your \usepackage command above; i.e. \usepackage[square, comma, sort&compress, numbers]{natbib}. Just thought I’d add this in case anyone else is experiencing the same difficulty.
nelu
thanks rachel, it was very helpful
prathap
Thanks Rachel, it helped !
Greg
Thanks Rachel, that’s what I needed.
saeed
Helped me 10 years after you posted the comment!
Virag Shah
\usepackage{cite} …worked for me
Eve
Thanks for the great post! Also, thank you to Rachel – I had the same problem, and that fixed it!
rozita
hi every one
I am typing my thesis in latex and i got big problem, I need to seprate my all references with comma , i am using
but i am getting instead of comma semicolon; for separating references {40;59;97} and whenever i am using
i am getting comma but i am having extra [] such as : [2],[3],[41]
My goal is just [2,3,41] how i can get this???
please help, this is so urgent.
thanks.
Rozita
tom
Hi Rozita,
Thanks for your comment. It suffices to load the
natbib
package. Here is a minimal example:You may also want to view the natbib reference sheet, a very nice collection of options provided by the package.
Best, Tom.
rozita
Dear Tom,
Thanks alot.
Best Regards
tom
You are welcome. Happy to help. Tom.
Muatez
Hi Tom,
Could you please help me with that???
I want to write three references in the same box?
Thanks in advance
tom
Hi Muatez,
It’s sufficient to use the
natbib
package withBest, Tom.
Sham
dear Tom,
how we can cite multiple references like [1-4] instead of [1,2,3,4]?
tom
Hi sham,
Please see my update of the post above where
natbib
was replaced withcite
. That should work.Best, Tom.
azim
Thankyou dear Rachel..I face the same problem as you mention.Now it works…May God Bless you….
Norman
This is a very good tip particularly to those fresh to the blogosphere.
Brief but very precise info Thanks for sharing this one.
A must read article!
Thangapandiyan
Hello
I am not using sort and conmpress. how i can define my natbib file. So, please provide natbib with sort and compress file.
Thank you
Thangapandiyan D.
tom
I’d strongly suggest to move to the more recent and extremely powerful biblatex package.
Cheers, Tom
Fernando
Hello there. Sorry if this post should go in a different section.
I have this problem: I renewed my pc and I installed MikTeX and TexMaker (the same programs I used before). However, when I try to run LaTeX an error message for the bibliography appears: “empty journal” or “empty booktitle” or “empty year” or “empty title”, something that did not happen before when I wrote an article (or any other reference) in the bilbiography without those details. I did not change anything from the previous version of my document.
I am using natbib package. Can you help me please? I have been trying to figure out what is happenning but I haven´t been able to understand the problem. I updated the LaTeX version using MikTex maintenance but nothing works so far.
Thank you very much for this blog.
Regads!
tom
Hi Fernando,
These error messages mean that some required field is missing in the bib entry. The error probably also tells you the identifier of the bib entry where the problem was encountered. You can find a list of required fields for the different entry types (article, book, conference, etc.) here.
HTH, Tom