How to order citations by appearance using BibTeX?
Asked Answered
S

13

393

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

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

Sapotaceous answered 27/9, 2008 at 22:34 Comment(5)
Helpful question (upvoted), but shouldn't this belong to tex.stackexchange.com ?Spikes
@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.Illyes
Delete the .aux and .bbl files and rebuildCounteroffensive
@EmadAghayi Does not work for me.Shani
I am facing the same issue with \documentclass[acmlarge]{acmart}Strigose
H
306

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}
Hermineherminia answered 28/9, 2008 at 4:21 Comment(4)
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.Sapotaceous
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}Prolific
I had to use \usepackage[backend=bibtex, sorting=none]{biblatex}, otherwise the references would not show up.Cooperman
In my case, using splncs03_unsrt.bst solved it.Deeann
B
198

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.

Berthaberthe answered 3/10, 2009 at 16:22 Comment(6)
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 linkLaoag
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.Ahab
Deleting .aux and .bbl files fixed my problem.Counteroffensive
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.Counteroffensive
using biblatex changing the style from numeric to ieee solved my issueJentoft
Worked like a charm (using Overleaf), thank you!Ringer
S
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?

Sapotaceous answered 27/9, 2008 at 22:36 Comment(3)
If you're using a custom BibTeX style, can you edit it to remove the SORT command?Davilman
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_ManagementMoniquemonism
If this doesn't work, try deleting the .bbl files, then rerun the latex compilationPopularize
P
24

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

Poteet answered 3/7, 2011 at 10:23 Comment(0)
E
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.

Evulsion answered 27/9, 2008 at 22:53 Comment(1)
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.)Hermineherminia
V
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

Vaughn answered 15/8, 2014 at 15:15 Comment(0)
B
3

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

Beltran answered 29/11, 2012 at 16:38 Comment(0)
V
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}
Venus answered 9/12, 2019 at 20:4 Comment(0)
E
3

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

\usepackage{cite}

\bibliographystyle{unsrt}

Eroto answered 9/7, 2021 at 0:1 Comment(0)
M
2

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

Martimartial answered 26/4, 2009 at 6:56 Comment(2)
Your claim about the format seems to contradict the accepted (and heavily upvoted) answer. Could you clarify?Fellowman
ieeetr doesn't seem to order in the order at which they appear.Greenheart
E
1

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

\usepackage{amsrefs}

Ezar answered 13/8, 2013 at 19:27 Comment(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).Fellowman
G
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}
Gonfalonier answered 28/5, 2013 at 8:42 Comment(0)
U
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}
Unproductive answered 15/1, 2017 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.