# Apalike but sort by last name of first author and year

I would like to use the natbib package in bibtex with the bibliographystyle apalike with a specific type of author-year ordering in the bibliography. I want items to generally be sorted/ordered alphabetically according to the author(s) name, but for authors, for which multiple items are known, the items should be ordered according to the publication year. Single-authored items should be separated for items with two authors, and the latter should be separated from items with three authors or more. apalike comes close to what I want to achieve, but there are some issues. As long as there are only single-author publications I get exactly what I want: Items are ordered according to the last name of the author. When multiple single-authored items are known for the same author, they are ordered according to the publication year. So far, so good.

But when the items known for the same author are not single-authored, the alphabet takes over and suddenly there will be items that were published later on (publication year), but appear in the bibliography before other items that were published earlier. A simple example would be: Joe (1972), Joe (1980), Joe & Mike (1999), Joe & Frank (2016), Joe & Mike & Tom (2000), Joe & Mike & Alexander (2011). Using the apalike style the bibliography would order them in the following way:

• Joe (1972)
• Joe (1980)
• Joe & Frank (2016)
• Joe & Mike (1999)
• Joe & Mike & Alexander (2011)
• Joe & Mike & Tom (2000)

but I would like to have it this way:

• Joe (1972)
• Joe (1980)
• Joe & Mike (1999)
• Joe & Frank (2016)
• Joe & Mike & Tom (2000)
• Joe & Mike & Alexander (2011)

Following Natbib sorting and citation order by appearance I tried to create my custom BST, which was supposed to be similar to apalike but circumvent the abovementioned issue. What I managed to do, is better than the original apalike style, but still not exactly what I want. When generating the custom BST using latex makebst I choose the following relevant options:

STYLE OF CITATIONS:

(a) Author-year with some non-standard interface

AUTHOR-YEAR SUPPORT SYSTEM (if author-year citations)

(l) Apalike for use with apalike.sty

ORDERING OF REFERENCES (if author-year citations)

(l) By label (Jones before Jones and James before Jones et al)


Single-authored items will still be ordered as I want. But with this new custom BST also "Authorname et al." items will be ordered as I want, i. e. following the year of publication after having checked the last name of the first author (what is actually checked is the label, but we shall not be concerned by this). What remains a problem are items which have exactly two authors (obviously, because for these no "et al." label is generated). These will still be ordered according to the alphabet. To take the example from above, I will get:

• Joe (1972)
• Joe (1980)
• Joe & Frank (2016)
• Joe & Mike (1999)
• Joe & Mike & Tom (2000)
• Joe & Mike & Alexander (2011)

So single-authored items and items with more than two authors are fine, but not items with two authors.

Below I provide a minimum example of my .tex file and a minimum example of some entries in the .bib file:

\documentclass[12pt,a4paper,hidelinks]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[authoryear,sort&compress]{natbib}       %Calls bibliography commands + Cite with author-year style (Harvard) instead of the numeric style.

\begin{document}

\section*{References}
\label{sec:References}
\citep{Owen1876,
Berman1977,
Berman1987,
Berman1992,
Berman1993,
Berman1993_Seymouria,
Berman2003_Aspidosaurus,
Berman2004,
Berman2010_Fedexia,
Berman2011_Rotaryus,
Berman2014,
Berman2015}

\bibliographystyle{apalike}
\bibliography{myrefs}

\end{document}


Here my minimal myrefs.bib file:

@Book{Owen1876,
title     = {{Descriptive and illustrated catalogue of the Fossil Reptilia of South Africa in the collection of the British Museum}},
publisher = {British Museum (Natural History)},
year      = {1876},
author    = {Richard Owen},
note      = {88 pp.},
url       = {http://gallica.bnf.fr/ark:/12148/bpt6k987042},
}

@Article{Berman1977,
author    = {Berman, David S},
title     = {{A new species of \textit{Dimetrodon} (Reptilia, Pelycosauria) from a non-deltaic facies in the Lower Permian of north-central New Mexico}},
journal   = {Journal of Paleontology},
year      = {1977},
volume    = {51},
number    = {1},
pages     = {108--115},
}

@Article{Berman1987,
author    = {David S. Berman and Robert R. Reisz and David A. Eberth},
title     = {{\textit{Seymouria sanjuanensis} (Amphibia, Batrachosauria) from the Lower Permian Cutler Formation of north-central New {Mexico} and the occurrence of sexual dimorphism in that genus questioned}},
journal   = {Canadian Journal of Earth Sciences},
year      = {1987},
volume    = {24},
number    = {9},
pages     = {1769--1784},
}

@Article{Berman1992,
author    = {David S. Berman and Stuart S. Sumida and R. Eric Lombard},
title     = {{Reinterpretation of the temporal and occipital regions in \textit{Diadectes} and the relationships of diadectomorphs}},
journal   = {Journal of Paleontology},
year      = {1992},
volume    = {66},
number    = {3},
pages     = {481--499},
}

@InCollection{Berman1993,
author    = {Berman, D. S.},
title     = {{Lower Permian vertebrate localities of New Mexico and their assemblages}},
booktitle = {{Vertebrate Paleontology in New Mexico}},
publisher = {New Mexico Museum of Natural History},
year      = {1993},
editor    = {Spencer G. Lucas AND Jiri Zidek},
volume    = {2},
pages     = {11--21},
}

@Article{Berman1993_Seymouria,
author   = {Berman, David S. and Martens, Thomas},
title    = {{First occurrence of \textit{Seymouria} (Amphibia: Batrachosauria) in the Lower Permian Rotliegend of central Germany}},
journal  = {Annals of Carnegie Museum},
year     = {1993},
volume   = {62},
number   = {1},
pages    = {63--79},
}

@Article{Berman2003_Aspidosaurus,
author   = {Berman, David S. and Lucas, Spencer G.},
title    = {{\textit{Aspidosaurus binasser} (Amphibia, Temnospondyli), a new species of Dissorophidae from the Lower Permian of Texas}},
journal  = {Annals of Carnegie Museum},
year     = {2003},
volume   = {72},
number   = {4},
pages    = {241--262},
}

@Article{Berman2004,
author    = {Berman, David S and Henrici, Amy C and Sumida, Stuart S and Martens, Thomas},
title     = {{New materials of \textit{Dimetrodon teutonis} (Synapsida: Sphenacodontidae) from the Lower Permian of Germany}},
journal   = {Annals of Carnegie Museum},
year      = {2004},
volume    = {73},
number    = {2},
pages     = {48--56},
}

@Article{Berman2010_Fedexia,
author    = {David S Berman and Amy C. Henrici and David K. Brezinski and Albert D. Kollar},
title     = {{A new trematopid amphibian (Temnospondyli: Dissorophoidea) from the Upper Pennsylvanian of Western Pennsylvania: earliest record of terrestrial vertebrates responding to a warmer, drier climate}},
journal   = {Annals of Carnegie Museum},
year      = {2010},
volume    = {78},
number    = {4},
pages     = {289--318},
}

@Article{Berman2011_Rotaryus,
author    = {David S Berman and Amy C. Henrici and Thomas Martens and Stuart S. Sumida and Jason S. Anderson},
title     = {{\textit{Rotaryus gothae}, a new trematopid (Temnospondyli: Dissorophoidea) from the Lower Permian of central {Germany}}},
journal   = {Annals of Carnegie Museum},
year      = {2011},
volume    = {80},
number    = {1},
pages     = {49--65},
}

@InCollection{Berman2014,
author    = {Berman, David S and Henrici, Amy C. and Sumida, Stuart S. and Martens, Thomas and Pelletier, Valerie},
title     = {{First European Record of a Varanodontine (Synapsida: Varanopidae): Member of a Unique Early Permian Upland Paleoecosystem, Tambach Basin, Central Germany}},
booktitle = {{Early Evolutionary History of the Synapsida}},
publisher = {Springer},
year      = {2014},
editor    = {Kammerer, Christian F. and Angielczyk, Kenneth D. and Fr{\"o}bisch, J{\"o}rg},
series    = {Vertebrate Paleobiology and Paleoanthropology},
chapter   = {5},
pages     = {69--86},
}

@InCollection{Berman2015,
author    = {David S. Berman AND Amy C. Henrici AND Spencer G. Lucas},
title     = {{Pennsylvanian-Permian Red Bed vertebrate localities of New Mexico an their assemblages}},
booktitle = {{Fossil Vertebrates in New Mexico}},
publisher = {New Mexico Museum of Natural History},
year      = {2015},
editor    = {Lucas, S. G. AND Sullivan, R. M.},
volume    = {68},
pages     = {65--76},
}


This generates the following document (only first page shown):

[

If we replace \bibliographystyle{apalike} with \bibliographystyle{myapalike}, i. e. my custom BST we get the following output (again only first page shown):

Note, that with the custom BST we are close to what I want to achieve. But the items with two authors do not follow the pattern I envision.

I think it should be pretty straight forward to generate my desired pattern in Bibtex (at least I guess so - there should be more people with this problem?), but I do not how. Note, that using \noopsort as suggested here Sort bibliographic entries according to first author's surname, then year, disregarding any further authors is not an option, since my bibliography is way too large to make such manual changes. If possible I would like to avoid having to use biblatex, and I would prefer an option that works for bibtex.

Is there maybe an alternative style that I am not aware of, that could help in this case? Or maybe a change when generating the custom BST? Or is it actually necessary to modify the custom BST manually? If so, how/what would need to be changed there?

As an additional question: How would I need to proceed if I wanted the all entries belonging to an author to just follow the year of publication, i. e. without separating single-authored items from items with two or more authors?

• Welcome to TeX.SE! Even though I disagree with your sorting logic, I hope you will get a solution to this issue. It is well formulated, researched, the goal is clear, and it contains all relevant information (except for your myapalike.bst, but it might not be required). Good luck. – thymaro Apr 9 at 22:21
• Thank you very much! Yes, let's hope for a useful answer. In regards to the myapalike.bst file: I thought it might not be necessary + I already had a hard time getting my post through the system, since it would be flagged as potential spam (I reckon that is because it is a bit long), so I decided to not include myapalike.bst. Regarding the sorting: Yes, maybe it is better to just use compress instead of sort&compress since the latter leads to in-text references not being in chronological but alphabetical order. Is that what you disagreed with? – user6475 Apr 10 at 8:50
• I'm not sure I understand your objective. Is the following interpretation correct? First, all the single-authored pieces by Berman, sorted chronologically; second, all publications by Berman and exactly one co-author, sorted chronologically rather than by surname of the second author, third, all triple-author pieces with Berman as the first author, sorted chronologically rather than by the surnames of the 2nd and 3rd author. Fourth, all quad-author pieces with Berman as the first author, again sorted chronologically; etc. Is this interpretation correct? If not, please clarify. – Mico Apr 10 at 10:02
• 1. all the single-authored pieces by Berman, sorted chronologically 2. all publications by Berman and exactly one co-author, sorted chronologically rather than by surname of the second author 3. all items with Berman as the first author and AT LEAST two co-authors, sorted chronologically rather than by the surnames of the 2nd, 3rd, 4th, 5th .... author – user6475 Apr 10 at 10:06

With a bit of playing around it is possible to get apalike.bst to sort entries only by the first author and then directly year and title.

The procedure to modify apalike.bst is as follows.

1. Locate apalike.bst on your machine. You can do this by typing kpsewhich apalike.bst into the command line/terminal. Alternatively, obtain a copy of the file from CTAN http://mirrors.ctan.org/biblio/bibtex/base/apalike.bst

2. Copy the file to a location where TeX can find it. The document directory will do fine. See also https://texfaq.org/FAQ-inst-wlcf

3. Rename the file to apalike-onesort.bst, say (the license of apalike.bst requires you to change the name if you modify the file)

4. Find FUNCTION {sort.format.names} (ll. 914-934) and replace the entire function with the much shorter

FUNCTION {sort.format.names}
{ 's :=
s num.names$#0 > { s #1 "{vv{ } }{ll{ }}{ f{ }}{ jj{ }}" format.name$ sortify }
{ "" }
if$}  5. Add a comment with your name, the current date and a short description of the changes to the top of the file. 6. Use \bibliographystyle{apalike-onesort} instead of \bibliographystyle{apalike} in your document. As alternative for steps 1 to 5 you can obtain the patched version of the file at https://gist.github.com/moewew/952669080e9cbc20f987d3ed42cf6606 With the new apalike-onesort.bst your MWE produces a bibliography sorted only by first author, then year and then title. If you want to sort all one-author items first, then all two-author items and finally all three-or-more-author items, replace the function with FUNCTION {sort.format.names} { 's := s num.names$ #0 >
{
s #1 "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$sortify s num.names$
duplicate$#3 < { int.to.str$ * }
{
pop$"3" * } if$
}
{ "" }
if\$
}


this adds "1", "2" or "3" after the author name for sorting and forces the desired scheme.

• Thank you very much. That is a solution to my additional question, i. e. if I wanted the references all entries belonging to an author to just follow the year of publication. How would I proceed with the original/main question, i. e. where the single-authored items are separate from 2-author-items and items with at least 3 authors? 2nd question: Is it possible to modify the code so that it sorts following this pattern: 1) Sort only by first author 2) Sort by year 3) Sort by additional authors 4) Sort by title So I have just introduced an additional condition (3) to what you did. – user6475 Apr 10 at 10:09
• @user6475 See the edit. Adding step (3) should be possible, but could be messy, I'll take a look. – moewe Apr 10 at 10:21
• Amazing, that is pretty much the solution I was looking for! Thank you very much! I will wait for a few days before I accept your answer to see whether you or someone else can help with the additional step 3. But if no one is able to provide that I shall accept your solution as it is. Thanks again! – user6475 Apr 10 at 12:19
• @user6475 I forgot a sortify in the second code block. I just edited it in. Try again with the new code, please. – moewe Jun 20 at 19:58