Biblatex: how to automatically sort citation by year (sortcites=ynt) when references are sorted by name (sorting=nyt)
Give the desired citation sort order at loading time. Then give the desired order for the bibliography in the new refcontext (\begin{refcontext}[sorting=<sorting>]...\end{refcontext}
) for \printbibliography
.
\documentclass{article}
\usepackage[backend=biber,
style=authoryear-comp, sorting=ynt,
% sortcites=true, % not needed here because it is implied by style=authoryear-comp,
]{biblatex}
\begin{filecontents}{\jobname.bib}
@book{key2000,
author = {Author, A.},
year = {2000},
title = {Alphabetical fist \& Year last},
publisher = {Publisher},
}
@book{key1900,
author = {Boathor, B.},
year = {1900},
title = {Alphabetical last \& Year first},
publisher = {Publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
Lorem \autocite{key2000, key1900}
ipsum \autocite{key1900, key2000}
\begin{refcontext}[sorting=nyt]
\printbibliography
\end{refcontext}
\end{document}
I used
\begin{refcontext}[sorting=nyt]
\printbibliography
\end{refcontext}
instead of the slightly shorter
\newrefcontext[sorting=nyt]
to be on the safe side if there are citations after the bibliography.
Some more explanation since this comes up more often.
biblatex
does not allow the sorting
option for \printbibliography
any more. It was removed because it could lead to weird sorting results.
Instead, now you use 'refcontexts' to control sorting. A refcontext controls sorting
, labelprefix
and sortingnamekeytemplate
and a few other things (possible more in the future).
An entry can appear in different refcontexts and any extra label data (extradate
, extraalpha
) will be recalculated based on the specific details (e.g. sorting) for each refcontext.
This can lead to slightly counter-intuitive results in very contrived examples because the sort order may be determined by data that is invisible in the citation itself and those data leads to different sorting results in different schemes.
Here is an admittedly very artificial example that shows this behaviour with your set-up. It can be much easier to achieve such an effect with other pairings of sort schemes. The trick here was that nyt
considers the volume
for sorting while ynt
does not.
\documentclass{article}
\usepackage[backend=biber, style=authoryear, sorting=ynt, sortcites]{biblatex}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@book{one,
author = {Elk, Anne},
title = {Title},
volume = {1},
note = {sorts first in ynt},
}
@book{two,
author = {Elk, Anne},
title = {Title},
note = {sorts first in nyt},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\autocite{one,two} \autocite{two,one}
\begin{refcontext}[sorting=nyt]
\printbibliography[title={\refname{} (sorting \texttt{nyt})}]
\end{refcontext}
\end{document}
A 'quick and dirty' solution (less good than moewe's one) is use biblatex
's sortcites=false
option, to enable the manual sorting of in-line citations.
\documentclass{article}
\usepackage[%
backend=biber,%
style=authoryear-comp,%
natbib=true,%
sorting=nyt,%
sortcites=false,
]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{A2000,
author = {Author, A.},
year = {2000},
title = {Alphabetical fist \& Year last},
publisher = {Publisher},
}
@book{B1900,
author = {Boathor, B.},
year = {1900},
title = {Alphabetical last \& Year first},
publisher = {Publisher},
}
@book{C1950,
author = {Coathor, C.},
year = {1950},
title = {Alphabetical last \& Year first},
publisher = {Publisher},
}
}
\end{filecontents}
\begin{document}
In-line citations should be manually sorted in the desired order, and the References list will be alphabetically sorted.
Example:
\begin{itemize}
\item This citation is manually year-sorted \citep{B1900, C1950, A2000},
\item this one is manually shuffled \citep{C1950, B1900, A2000}.
\end{itemize}
\printbibliography[]
\end{document}