381

By default (using the plain style) BibTeX orders citations alphabetically.

How to order the citations by order of appearance in the document?

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Brendan
  • 18,771
  • 17
  • 83
  • 114

13 Answers13

301

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}
carlsky
  • 78
  • 1
  • 7
Will Robertson
  • 62,540
  • 32
  • 99
  • 117
  • 2
    One apparent advantage of the biblatex package that caused me to accept this answer is that it allows editing up reference styles using TeX macros rather than weird BibTeX voodoo. Other packages may be better for a quicker/more reliable solution. – Brendan Oct 07 '08 at 09:17
  • 2
    I need to add that if you are using biblatex. It would be better use \addbibresource instead \bibliography. So `\addbibresource{journals.bib,phd-references.bib}` – Custodio Apr 10 '12 at 16:53
  • 2
    I had to use `\usepackage[backend=bibtex, sorting=none]{biblatex}`, otherwise the references would not show up. – Archisman Panigrahi Jun 18 '21 at 06:34
  • In my case, using `splncs03_unsrt.bst` solved it. – Nav Aug 03 '23 at 10:51
192

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.

Riaz
  • 18
  • 2
  • 7
    if you are writing a paper for ACM Publication then `unsrt` would be better than `ieeetr` since the latter is meant for IEEE paper which has a slightly different formatting. `unsrt` and `abbrv` produces the same type of formatting. You might want to take a look at this [link](http://sites.stat.psu.edu/~surajit/present/bib.htm) – Ash Catchem Jun 19 '14 at 22:24
  • **The simple answer arises!** While [Will Robertson](https://stackoverflow.com/users/4161/will-robertson)'s `biblatex`-centric [answer](https://stackoverflow.com/a/145207/2809027) is ultimately the way forward for the LaTeX community, LyX's continued lack of built-in support for `biblatex` is an enormous (and increasingly embarrassing) blocker. It's been eight years since this question was first posed! I'll never grok LyX's developer priorities. It's 2016. Driverless cars and portable supercomputers are a thing, yet here we remain – chained to the same execrable BibTeX stone of shame. – Cecil Curry Feb 15 '16 at 00:55
  • Deleting *.aux* and *.bbl* files fixed my problem. – E A Aug 05 '18 at 22:59
  • 3
    It doesn't work in the Overleaf application. I removed them in Overleaf by https://www.overleaf.com/learn/how-to/Clearing_the_cache but it doesn't fix the problem. – E A Jun 10 '19 at 17:32
  • using biblatex changing the style from numeric to ieee solved my issue – LazerDance Apr 06 '21 at 12:16
25

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?

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
Brendan
  • 18,771
  • 17
  • 83
  • 114
  • 4
    If you're using a custom BibTeX style, can you edit it to remove the SORT command? – ChrisN Sep 27 '08 at 23:24
  • By default, the wiki page recommends you plain. If you copy-paste carelessly, you'll be using plain instead of unsrt style. http://en.wikibooks.org/wiki/LaTeX/Bibliography_Management – András Gyömrey Jul 10 '13 at 14:07
  • If this doesn't work, try deleting the .bbl files, then rerun the latex compilation – Matthias Luh Feb 02 '23 at 11:05
23

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" ;)

sdaau
  • 36,975
  • 46
  • 198
  • 278
14

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.

lindelof
  • 34,556
  • 31
  • 99
  • 140
  • 7
    natbib only affects the typesetting of the \cite commands in the document itself. Having said that, it is distributed with unsrtnat.bst to achieve the effect sought by the original poster. (I'd recommend biblatex these days over natbib, unless absolute stability is most important.) – Will Robertson Sep 28 '08 at 05:19
6

I'm a bit new to Bibtex (and to Latex in general) and I'd like to revive this old post since I found it came up in many of my Google search inquiries about the ordering of a bibliography in Latex.

I'm providing a more verbose answer to this question in the hope that it might help some novices out there facing the same difficulties as me.

Here is an example of the main .tex file in which the bibliography is called:

\documentclass{article}
\begin{document}

So basically this is where the body of your document goes.

``FreeBSD is easy to install,'' said no one ever \cite{drugtrafficker88}.

``Yeah well at least I've got chicken,'' said Leeroy Jenkins \cite{goodenough04}.

\newpage
\bibliographystyle{ieeetr} % Use ieeetr to list refs in the order they're cited
\bibliography{references} % Or whatever your .bib file is called
\end{document}

...and an example of the .bib file itself:

@ARTICLE{ goodenough04,
AUTHOR    = "G. D. Goodenough and others", 
TITLE     = "What it's like to have a sick-nasty last name",
JOURNAL   = "IEEE Trans. Geosci. Rem. Sens.",
YEAR      = "xxxx",
volume    = "xx",
number    = "xx",
pages     = "xx--xx"
}
@BOOK{ drugtrafficker88,
AUTHOR    = "G. Drugtrafficker", 
TITLE     = "What it's Like to Have a Misleading Last Name",
YEAR      = "xxxx",
PUBLISHER = "Harcourt Brace Jovanovich, Inc."
ADDRESS   = "The Florida Alps, FL, USA"
}

Note the references in the .bib file are listed in reverse order but the references are listed in the order they are cited in the paper.

More information on the formatting of your .bib file can be found here: http://en.wikibooks.org/wiki/LaTeX/Bibliography_Management

3

I often use the bibliography style natbib because it supplies quite complete set of formats as well as tags for us.

Tung
  • 1,579
  • 4
  • 15
  • 32
3

Add this if you want the number of citations to appear in order in the document they will only be unsorted in the reference page:

\bibliographystyle{unsrt}
Pankwood
  • 1,799
  • 5
  • 24
  • 43
Malak
  • 37
  • 7
3

I used the following in overleaf and become in ascending order:

\usepackage{cite}

\bibliographystyle{unsrt}

sepideha
  • 1,669
  • 1
  • 11
  • 14
2

with unsrt the problem is the format. use \bibliographystyle{ieeetr} to get refences in order of citation in document.

Thiem Nguyen
  • 6,345
  • 7
  • 30
  • 50
1

If you happen to be using amsrefs they will override all the above - so comment out:

\usepackage{amsrefs}

Wilq
  • 2,245
  • 4
  • 33
  • 37
Guest
  • 11
  • 1
  • 1
    Welcome to Stack Overflow! Your answer doesn't appear to actually answer the question posed. Your information could be valuable, but it is probably better suited as comment to one of the other answers (once you have obtained the necessary reputation to post comments). – Zero3 Jul 16 '15 at 13:20
0

The datatool package offers a nice way to sort bibliography by an arbitrary criterion, by converting it first into some database format.

Short example, taken from here and posted for the record:

\documentclass{article}

\usepackage{databib}

\begin{document}
% First argument is the name of new datatool database
% Second argument is list of .bib files
\DTLloadbbl{mybibdata}{acmtr}
% Sort database in order of year starting from most recent
\DTLsort{Year=descending}{mybibdata}
% Add citations
\nocite{*}

% Display bibliography
\DTLbibliography{mybibdata}
\end{document}
kebs
  • 6,387
  • 4
  • 41
  • 70
0

I use natbib in combination with bibliographystyle{apa}. Eg:

\begin{document}

The body of the document goes here...

\newpage

\bibliography{bibliography} % Or whatever you decided to call your .bib file 

\usepackage[round, comma, sort&compress ]{natbib} 

bibliographystyle{apa}
\end{document}
Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49