在線引用期間使用 Smith (2010a, 2010b) 代替 Smith (2010a, b)

在線引用期間使用 Smith (2010a, 2010b) 代替 Smith (2010a, b)

我正在使用 natbib 套件進行寫作。

例如,Smith 有 2 篇論文,均發表於 2010 年。現在,當我使用 \citet{Sm1,Sm2} 引用論文時,它會產生 Smith (2010a, b)。但我希望它像史密斯(2010a,2010b)一樣。誰能幫我?

答案1

我會進行修補\NAT@citex以避免年度檢查,因此您不需要提前知道年份。它適用於任何情況。

\begin{filecontents*}{\jobname.bib}
@article{sma,
 author={Smith, J.},
 title={A},
 journal={B},
 year={2014},
}
@article{smb,
 author={Smith, J.},
 title={C},
 journal={D},
 year={2014},
}
\end{filecontents*}
\documentclass{article}
\usepackage[authoryear,round]{natbib}
\usepackage{xpatch}

% patch \NAT@citex to always use the year
\makeatletter
\xpatchcmd{\NAT@citex}
  {\ifx\NAT@last@yr\NAT@year}
  {\iffalse}
  {}{}
\xpatchcmd{\NAT@citex}
  {\ifx\NAT@last@yr\NAT@year}
  {\iffalse}
  {}{}
\makeatother

\begin{document}
\citep{sma,smb}

\citet{sma,smb}

\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

像往常一樣,filecontents*環境只是為了使範例自包含。

在此輸入影像描述

解釋。命令\NAT@citex是流程的主要部分;在兩個地方確實如此

\ifx\NAT@last@yr\NAT@year
  <something if the current citation has the same year as the preceding one>
\else
  <otherwise>
\fi

透過補丁,我們將條件(第一行)更改為\iffalse,因此永遠不會遵循“true”分支。

答案2

假設兩個條目的鍵是sm1sm2,您可以透過編寫來實現您的目標

\citeauthor{sm1} (\citeyear{sm1}, \citeyear{sm2})

備註:該natbib套件具有選項sortcompresssort&compress,但它們似乎主要面向數位式引用標註。對於作者年份風格的引用標註,該包似乎沒有提供諸如nosort或 之類的選項nocompress——因此需要上面提供的看起來很麻煩的代碼。

相關內容