前言
如题,有时候在写latex项目的时候,想改一下参考文献的引用格式为“作者+年份”,从而更加方便看到这篇论文是哪位作者在哪一年写的。故在此记录之,并记录Package natbib Error: Bibliography not compatible with author-year
问题的解决方案。
1 步骤
1)在\begin{document}
前添加:
\usepackage[round, sort]{natbib}
这个natbib宏包是latex cite功能的再实现及扩展,功能很强大,可详见其pdf:[3]
2)在\begin{document}
后,\end{document}
前添加:
\bibliographystyle{plainnat}
\bibliography{mybib}
其中mybib指向的是mybib.bib
文件,里面存放了很多bibtex格式的参考文献。如:
@article{tang2020can,
title={Can We Use Stack Overflow as a Source of Explainable Bug-fix Data?},
author={Tang, Henry and Nadi, Sarah},
journal={arXiv preprint arXiv:2004.08378},
year={2020}
}
3)在正文中引用:
\textbf{Can We Use Stack Overflow as a Source of Explainable Bug-fix Data?} \citep{tang2020can}.
\citep
也可以换为\citet
。对应的\citep*
,\citet*
则是显示所有作者 [2]。
4)此时编译:
如题,可以看到效果。是我们想要的“作者,年份”格式。
2 可能出现的问题:! Package natbib Error: Bibliography not compatible with author-year
在修改bib style之后,重新编译发现出现了这样的错误:
! Package natbib Error: Bibliography not compatible with author-year
解决方案:
移除之前的latex项目的编译产生的文件。如图:
删除之后,重新编译,就不会报错了。
3 小结
本文主要参考:[4]
之前我看到的解决方案是:[1],其中说可以改为:
\bibliographystyle{apalike}
\bibliography{bibfile}
但是这个似乎需要\usepackage[round, sort]{natbib}
的加持(即要引入这个宏包),不然会报错。