There may be similar question, but none of them does really anwer the following one. I would like to have the references sorted by firt author's surname, but the number should correspond to the appearnce in the text using natbib, e.g., it should look like

[42]  A. Einstein, Relativity, 1927...
[1]   R. P. Feynmann, Magnetism, 1957...
[102] J. C. Maxwell, Electricity, 1873...

Thanks for your help.

  • 2
    Welcome. // You can increase the chances for replies, when you add code to your request, which we can use to copy, compile and learn about your current attempts. Thanks. // See also the Related links to the right, or try the search options on this site.
    – MS-SPO
    Commented Sep 22, 2022 at 7:42
  • In particular, do please tell if you employ the natbib citation management package and, if so, the options you employ for this package. Next, which bibliography style do you use?
    – Mico
    Commented Sep 22, 2022 at 7:49
  • 1
    are you sure you want that? I'm sure it would be possible to force it but I have never seen such a scheme, and it will be rather confusing to your readers. Especially on paper where you can not just follow a link, how is a reader supposed to find the citation referenced by [42] if the list is not in order? Commented Sep 22, 2022 at 8:04

1 Answer 1


The following contains a hack to change the numbers. Note that it is rather confusing to the readers.

The idea is to sort alphabetically using the plainnat style, but change the code that assigns the number to each alphabetically ordered item.

To do so, the code should keep track of the cite order in the document. This is done by adding some code to the \cite command that stores a counter using the cite key as a macro name. This counter should only be assigned on the first mention of a citation, so you can check for existence of the macro named using the cite key.

Then the bibliography code is modified (specifically \@lbibitem) to use the citekey-macro as the number instead of the regular NAT@ctr counter.

Modifying the commands can be done using \patchcmd and \apptocmd from etoolbox, which also provides \csxdef and \ifcsundef.


  author = {Einstein, A.},
  title = {Relativity},
  year = {1927}
  author = {Feynmann, R.P.},
  title = {Magnetism},
  year = {1957}
  author = {Maxwell, J.C.},
  title = {Electricity},
  year = {1873}

% counter to keep track of document citation order

% use the cite key macro (argument #2 of \bibitem and \@lbibitem) as number
% instead of a sequential NAT@ctr

% store the current value of the myunsrt counter in a macro
% using the cite key (argument #3) as macro name
\ifcsundef{#3}% don't renumber if it already exists
\cite{magnetism}, \cite{relativity}, \cite{electricity}


enter image description here

Surprisingly, it worked with hyperref out of the box, producing correct links.

Note that the cite keys have to be suitable as macro names to use this hack.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .