[Tex/LaTex] Sorting citations and bibliography using natbib and plainnat

citingmultiple-citationsnatbib

I'm writing a paper in LaTeX. I'm working with the natbib package and the plainnat style for the citations and references. The problem is how the citations and the references is being sorted.

I want the citations sorted by year (for the same year alphabeticaly) and the references sorted alphabeticaly by the author's last name. How can I do it?

My code:

    \documentclass[12pt,a4paper]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
    \usepackage[comma,authoryear,round]{natbib}
    \usepackage[none]{hyphenat} 
    \bibliographystyle{plainnat}
    \setcitestyle{citesep={;}}

    \begin{filecontents}{\jobname.bib}
    @book{A,
     author = {Ho, L. and Auntz, K. and Zwitter, B. F. and Valencia, D.},
     year = {2010},
     title = {Title Example 1},
    }
    @book{B,
     author = {Ho, L. and Yelp, A. and Richter, G. and Gregory, K. T.},
     year = {2005},
     title = {Title Example 2},
    }
    @book{C,
     author = {Ho, L. Abrook, H. and Dolman, R. G. and Fjing, H. and Ho, S. and Xerem, R.},
     year = {2013},
     title = {Title Example 3},
    }
    }
    @book{D,
     author = {Di Bernardo, L. and Mc Daug, C. and Coelho, L},
     year = {2000},
     title = {Title Example 4},
    }
    @book{E,
     author = {Gomes, L. N. L. and Ginoris, Y. P and Brand\~{a}o, C. C. S.},
     year = {2010},
     title = {Title Example 5},
    }
    \end{filecontents}


    \begin{document}
    Hi, this is an example. First a citation \citep{A,B},
then an inline citation \citet{B}.
Another citation \citep{C,D} and
the last one \citep{A,E}
    \bibliography{\jobname}
    \end{document}

And the result with the observations:

enter image description here

Best Answer

If you add the sort option to natbib

    \usepackage[sort,comma,authoryear,round]{natbib}

then it sorts first by author name and then by year. You seem to want to sort by year first and then author name. I don't believe natbib has support for that.

Edit: It's pretty easy to modify a copy of plainnat.bst to sort first by year than by name. This doesn't seem to be what you're showing in your example, but maybe it's what you want.

First, make a copy of plainnat.bst in your current directory and call it yearnat.bst. On my machine I can do that via

$ cp `kpsewhich plainnat.bst` yearnat.bst

Edit yearnat.bst and change the presort function to the following.

FUNCTION {presort}
{ calc.label
  label sortify
  "    "
  *
  year field.or.null sortify
  "    "
  *
  type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
        'editor.organization.sort
        { type$ "manual" =
            'author.organization.sort
            'author.sort
          if$
        }
      if$
    }
  if$
  *
  "    "
  *
  cite$
  *
  #1 entry.max$ substring$
  'sort.label :=
  sort.label *
  #1 entry.max$ substring$
  'sort.key$ :=
}

All this does is move the year field to the beginning of the sort key.

Now compile your example with the addition of the sort option as above and the \bibliographystyle{yearnat}. Here's the result.

enter image description here

You can see that everything is sorted first by year, and then by author. If you want to know how that works, you should read btxhak (or by running texdoc btxhak).

Related Question