# Package natbib Error: Bibliography not compatible with author-year citations (Elsevier template)

I am getting an error "Package natbib Error: Bibliography not compatible with author-year citations. (natbib) Press to continue in numerical citation style."

I am to generate the reference number at the text which works great and gives me good results on the PDF but still getting error!

%%%%%%%%%%%%%Elsevier template %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[5p,preprint,authoryear]{elsarticle}

\journal{Energy}
\setcitestyle{square}
\usepackage{times}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{amsmath}
\usepackage{circuitikz}
\usetikzlibrary{patterns}
\usepackage{array,booktabs}
\usepackage{natbib}
\usepackage{tikz}
\usepackage{float}

\begin{document}

\begin{frontmatter}

\begin{abstract}
Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex
\end{abstract}

\end{frontmatter}

\section{Introduction}
Latex Latex Latex  Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex Latex \cite{nazari2019optimal}.

\biboptions{sort&compress}
\bibliographystyle{elsarticle-num}
\bibliography{citation.bib}

\end{document}

\endinput
%%
%% End of file elsarticle-template-harv.tex'.


my citation

@article{nazari2019optimal,
title={Optimal energy management for a mild hybrid vehicle with electric and hybrid engine boosting systems},
author={Nazari, Shima and Siegel, Jason and Stefanopoulou, Anna},
journal={IEEE Transactions on Vehicular Technology},
volume={68},
number={4},
pages={3386--3399},
year={2019},
publisher={IEEE}
}


Since it looks like you want authoryear-style citation call-outs, you should change

\bibliographystyle{elsarticle-num}


to

\bibliographystyle{elsarticle-harv}


While you're at it, you should probably also change

\setcitestyle{square}


to

\setcitestyle{round}


Then, delete all auxiliary files and perform a full recompile cycle -- LaTeX, BibTeX, and LaTeX twice more.

• Sorry, I am actually was trying to get the reference number not the author and year – soooleh Sep 5 at 15:14
• @soooleh - If you do not want authoryear-style citation call-outs, you should most definitely not specify authoryear as one of the document class options. – Mico Sep 5 at 15:34
• what do you mean by not specifying authoryear? I am still getting the natbib! can you please give me an example – soooleh Sep 5 at 15:39
• @soooleh - You ask what I "mean by not specifying authoryear". Easy: Change \documentclass[5p,preprint,authoryear]{elsarticle} to \documentclass[5p,preprint]{elsarticle}. Incidentally, the elsarticle document class loads natbib automatically; hence, no need to run \usepackage{natbib}` explicitly. Incidentally, what do you mean by "I am still getting the natbib!"? – Mico Sep 5 at 15:44
• Great! thank you so much for being patient with me. – soooleh Sep 5 at 17:12