Document Classeselsarticle, natbib | Possible Clash

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
sjaak
Posts: 1
Joined: Fri Mar 02, 2012 12:24 am

elsarticle, natbib | Possible Clash

Post by sjaak »

Hi I am unable to get this to work on my Gummi install at home, while it works without problems at work:

Code: Select all

\documentclass[review,times,authoryear]{elsarticle}
\usepackage[english]{babel}
\usepackage{natbib}

\begin{document}
Hello \cite{lamport94}

\begin{thebibliography}{9}
  \bibitem{lamport94}
    Leslie Lamport,
    \emph{\LaTeX: A Document Preparation System}.
    Addison Wesley, Massachusetts,
    2nd Edition,
    1994.
\end{thebibliography}

\end{document}
The error I get is:
Package natbib Error: Bibliography not compatible with author-year citations.
I am not sure I understand this error. I have tried various other \bibitem formats, without luck.

When I remove "authoryear" in the options for elsarticle, it works.

\listfiles gives me

Code: Select all

elsarticle.cls    2009/09/17, 1.20b: Elsevier Ltd
natbib.sty    2009/07/16 8.31 (PWD, AO)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

elsarticle, natbib | Possible Clash

Post by localghost »

The problem is not related to the elsarticle class. The natbib package does not expect that you do your bibliography by hand with the thebibliography environment. Probably it will help if you just replace it by \bibliographystyle{unsrtnat} (or something similar). The below example works for me.

Code: Select all

\begin{filecontents*}{\jobname.bib}
@book{lamport94,
  author = {Leslie Lamport},
  edition = {Second},
  note = {User's Guide and Reference Manual},
  publisher = {Addison-Wesley},
  title = {\LaTeX\ -- A Document Preparation System},
  year = {1994}
}
\end{filecontents*}
\documentclass[review,times,authoryear,english]{elsarticle}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{natbib}

\bibliographystyle{unsrtnat}

\begin{document}
  Hello \cite{lamport94}

  \bibliography{\jobname}
\end{document}
I also tried this example with Gummi, but it seems not to recognize the file written by the filecontents(*) environment. But if the bibliography database file is present separately, the code should also compile with Gummi. However, I could not make Gummi recognize the database file (*.bib).


Best regards and welcome to the board
Thorsten
Post Reply