# Incorrect sorting of citations when captions are used, even without a list of figures

There are many questions on this board about how citations can be numbered in the incorrect order when using the unsrt bibliography style. This is when a citation is used in a caption when a list of figures is present. The citations which appear in the list of figures get numbered before those in the body of the text. When the figures are placed, their citations appear to be out of order with the rest of the document.

One possible answer is to use the \notoccite package. Another is to use the optional argument to \caption to prevent the citation appearing in the list of figures.

In the question Unsorted citations and floats, a MWE was shown (reproduced below) that demonstrates that this problem can happen even when there is no list of figures. A hack was posted that partially solves the problem for the MWE case, but doesn't fully explain or resolve the issue.

I want to know:

1. Why does Latex produce this behaviour?
2. Is there an elegant solution that doesn't redefine internal macros?

MWE (credit to Alan Munn):

\documentclass[12pt,oneside]{book}
\usepackage[super,sort&compress]{natbib}
\bibpunct{[}{]}{,}{s}{}{}
\bibliographystyle{unsrtnat}
\usepackage{hyperref}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{filecontents}
\usepackage{caption}
\begin{filecontents}{\jobname.bib}
@incollection{Baauw2001,
Author = {Sergio Baauw},
Booktitle = {Proceedings of the 25th Annual Boston University Conference on Language Development},
Editor = {A. H.-J. Do and L. Dom{\'\i}nguez and A. Johansen},
Pages = {82-93},
Title = {Expletive determiners in child Dutch and Spanish},
Year = {2001}}

@article{barker1998,
Author = {Chris Barker},
Journal = {Natural Language \& Linguistic Theory},
Pages = {679-717},
Title = {Partitives, Double Genitives and Anti-Uniqueness},
Volume = {16},
Year = {1998}}

@book{Berwick1985,
Author = {Berwick, Robert C.},
Publisher = {MIT Press},
Title = {Acquisition of syntactic knowledge},
Year = {1985}}

@phdthesis{Carlson1977,
Author = {Carlson, Gregory N.},
School = {University of Massachusetts, Amherst},
Title = {Reference to Kinds in {E}nglish},
Year = {1977}}

\end{filecontents}

\begin{document}

\chapter{A chapter}
\lipsum
Some text.\cite{Carlson1977}
\lipsum[3]
\cite{Barker1998,Baauw2001}
\begin{figure}[tbp]
\centering
\includegraphics[width=.5\textwidth]{demo.jpg}
\captionof{figure}[A figure from Berwick]{A figure from \protect\cite{Berwick1985}}
\end{figure}
\lipsum[2]
\bibliography{\jobname}
\end{document}


The citations are numbered in the order they are set but in your case the figure floats backwards, so you get [4] in the figure at the top of the page, the usual solution is to consider this OK as floats are explicitly not in the main document flow so order is a bit hard to define. If you do not want floats ever to float backwards add
\usepackage{flafter}

then t will allow the float to go to the top of a later page but not allow it to float backwards to the top of this page, so in this case b is chosen and the float appears at the end, with the citation [4].
Alternatively if you want the float at the top, either move the figure environment earlier in the source, before the \cite that is making 2,3, or place a \nocite{...} at a similar point, where ... is the key of the reference in the figure caption.
• An alternative adjustment is to add a \nocite{...} at an appropriate point in the text, where ... is the key of the ref in the figure. In the given MWE \nocite{Berwick1985}\cite{Carlson1977} at the first cite gets the numering right. – Andrew Swann Jan 31 '18 at 16:41