How to order citations by appearance using BibTeX?
By default (using the plain
style) BibTeX orders citations alphabetically.
How to order the citations by order of appearance in the document?
Solution 1:
There are three good answers to this question.
- Use the
unsrt
bibliography style, if you're happy with its formatting otherwise - Use the
makebst
(link) tool to design your own bibliography style
And my personal recommendation:
- Use the
biblatex
package (link). It's the most complete and flexible bibliography tool in the LaTeX world.
Using biblatex
, you'd write something like
\documentclass[12pt]{article}
\usepackage[sorting=none]{biblatex}
\bibliography{journals,phd-references} % Where journals.bib and phd-references.bib are BibTeX databases
\begin{document}
\cite{robertson2007}
\cite{earnshaw1842}
\printbibliography
\end{document}
Solution 2:
Change
\bibliographystyle{plain}
to
\bibliographystyle{ieeetr}
Then rebuild it a few times to replace the .aux
and .bbl
files that were made when you used the plain style.
Or simply delete the .aux
and .bbl
files and rebuild.
If you use MiKTeX you shouldn't need to download anything extra.
Solution 3:
The best I came up with is using the unsrt
style, which seems to be a tweaked plain
style. i.e.
\bibliographystyle{unsrt}
\bibliography{bibliography}
However what if my style is not the default?
Solution 4:
Just a brief note - I'm using a modified version of plain.bst sitting in the directory with my Latex files; it turns out having sorting by order of appearance is a relatively easy change; just find the piece of code:
...
ITERATE {presort}
SORT
...
... and comment it - I turned it to:
...
%% % avoid sort:
%% ITERATE {presort}
%%
%% SORT
...
... and then, after running bibtex
, pdflatex
, pdflatex
- the citations will be sorted by order of appearance (that is, they will be unsorted :) ).
Cheers!
EDIT: just realized that what I wrote is actually in the comment by @ChrisN: "can you edit it to remove the SORT command" ;)
Solution 5:
You answered your own question---unsrt
is to be used when you want references to ne listed in the order of appeareance.
But you might also want to have a look at natbib, an extremely flexible citation package. I can not imagine living without it.