382

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

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

5
  • 53
    Helpful question (upvoted), but shouldn't this belong to tex.stackexchange.com ? Jun 4, 2014 at 21:59
  • 21
    @ChthonicProject, I don't think tex.stackexchange.com started until 2010 and this question is from 2008. Also, the question would be too old to migrate, so it lives on here. Aug 6, 2015 at 14:01
  • 4
    Delete the .aux and .bbl files and rebuild
    – E A
    Aug 5, 2018 at 23:00
  • @EmadAghayi Does not work for me. Sep 21, 2020 at 12:49
  • I am facing the same issue with \documentclass[acmlarge]{acmart} Jan 27, 2021 at 13:49

13 Answers 13

303

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}
4
  • 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 7, 2008 at 9: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, 2012 at 16:53
  • 2
    I had to use \usepackage[backend=bibtex, sorting=none]{biblatex}, otherwise the references would not show up. Jun 18, 2021 at 6:34
  • In my case, using splncs03_unsrt.bst solved it.
    – Nav
    Aug 3 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.

5
  • 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 Jun 19, 2014 at 22:24
  • The simple answer arises! While Will Robertson's biblatex-centric answer 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. Feb 15, 2016 at 0:55
  • Deleting .aux and .bbl files fixed my problem.
    – E A
    Aug 5, 2018 at 22:59
  • 3
    It doesn't work in the Overleaf application. I removed them in Overleaf by overleaf.com/learn/how-to/Clearing_the_cache but it doesn't fix the problem.
    – E A
    Jun 10, 2019 at 17:32
  • using biblatex changing the style from numeric to ieee solved my issue
    – LazerDance
    Apr 6, 2021 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?

3
  • 4
    If you're using a custom BibTeX style, can you edit it to remove the SORT command?
    – ChrisN
    Sep 27, 2008 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. en.wikibooks.org/wiki/LaTeX/Bibliography_Management Jul 10, 2013 at 14:07
  • If this doesn't work, try deleting the .bbl files, then rerun the latex compilation Feb 2 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" ;)

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.

1
  • 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.) Sep 28, 2008 at 5: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.

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}
3

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

\usepackage{cite}

\bibliographystyle{unsrt}

2

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

2
  • Your claim about the format seems to contradict the accepted (and heavily upvoted) answer. Could you clarify?
    – Zero3
    Jul 16, 2015 at 13:16
  • ieeetr doesn't seem to order in the order at which they appear.
    – vineeshvs
    Apr 15, 2021 at 3:45
1

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

\usepackage{amsrefs}

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, 2015 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}
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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.