[LaTeX] 將參考文獻的引用格式從編號改爲 “作者,年份” 及可能出現的問題(Package natbib Error: Bibliography not compatible...)解決

前言

如題,有時候在寫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}的加持(即要引入這個宏包),不然會報錯。

參考文獻

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章