BibTeX, biblatex and biberSort Citations by Reference Number

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
andankert
Posts: 3
Joined: Sat Aug 10, 2013 6:09 pm

Sort Citations by Reference Number

Post by andankert »

Hi,

I'm just finalizing my thesis and have a minor design question. If I reference some papers multiple times in different combinations, I cannot keep track of their order in the bibliography. That means, some references will occur in the document like this [43,12,23,13,14]. Is there a way that the order is automatically adjusted to read [12,13,14,23,43], or even better [12-14,23,43]?

Thanks!
Last edited by andankert on Mon Aug 12, 2013 2:56 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Sort Citations by Reference Number

Post by cgnieder »

Hi andankert,

Welcome to the LaTeX coummunity!

Please provide us with a Infominimal working example (if you don't know what that is please follow the link). There are several ways to cite and create bibliographies and any possible solutions depends on how you do it.

Regards
site moderator & package author
andankert
Posts: 3
Joined: Sat Aug 10, 2013 6:09 pm

Sort Citations by Reference Number

Post by andankert »

Hi,

since it includes a bibliography file, I made this example, explaining my problem at the same time:

Code: Select all

\documentclass{book}
\usepackage{filecontents}

\begin{filecontents}{bibfile.bib}
@article{Nobody01,
  author = "Nobody A",
  title = "My Article A",
  journal="J1",
  year = "2002"
}
@article{Nobody02,
  author = "Nobody B",
  title = "My Article B",
  journal="J1",
  year = "2001"
}
@article{Nobody03,
  author = "Nobody C",
  title = "My Article C",
  journal="J1",
  year = "2006"
}
\end{filecontents}

\begin{document}
First I introduce some citations from here \cite{Nobody01,Nobody02} and here \cite{Nobody03}. But then I just talk about \cite{Nobody03} and \cite{Nobody01}, not taking care of the order \cite{Nobody03,Nobody01}, which switches the order. Especially if I do this \cite{Nobody03,Nobody01,Nobody02}, it doesn't write [1-3]. In article the reordering works though! Maybe just in my bib-style or so? 
\bibliographystyle{vancouver}
\bibliography{bibfile}

\end{document}
Thanks for your help!

André
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Sort Citations by Reference Number

Post by cgnieder »

Good MWE! :)

You can add

Code: Select all

\usepackage[numbers,sort]{natbib}
to your preamble or even

Code: Select all

\usepackage[numbers,sort&compress]{natbib}
The latter would format the list as [1--3] while the former gives [1, 2, 3].

Code: Select all

\documentclass{book}
\usepackage[numbers,sort]{natbib}
\usepackage{filecontents}

\begin{filecontents}{bibfile.bib}
@article{Nobody01,
  author = "Nobody A",
  title = "My Article A",
  journal="J1",
  year = "2002"
}
@article{Nobody02,
  author = "Nobody B",
  title = "My Article B",
  journal="J1",
  year = "2001"
}
@article{Nobody03,
  author = "Nobody C",
  title = "My Article C",
  journal="J1",
  year = "2006"
}
\end{filecontents}

\begin{document}
First I introduce some citations from here \cite{Nobody01,Nobody02} and here
\cite{Nobody03}. But then I just talk about \cite{Nobody03} and
\cite{Nobody01}, not taking care of the order \cite{Nobody03,Nobody01}, which
switches the order. Especially if I do this \cite{Nobody03,Nobody01,Nobody02},
it doesn't write [1-3]. In article the reordering works though! Maybe just in
my bib-style or so?

\bibliographystyle{vancouver}
\bibliography{bibfile}

\end{document}
Regards
site moderator & package author
andankert
Posts: 3
Joined: Sat Aug 10, 2013 6:09 pm

Re: Sort Citations by Reference Number

Post by andankert »

Excellent! That did the job!

Thanks a lot Clemens!!!

André
Post Reply