![如何更改具有多个引用的 \citeauthor 的分隔符并在最后两个引用之间添加“and”?](https://linux22.com/image/240335/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%E5%85%B7%E6%9C%89%E5%A4%9A%E4%B8%AA%E5%BC%95%E7%94%A8%E7%9A%84%20%5Cciteauthor%20%E7%9A%84%E5%88%86%E9%9A%94%E7%AC%A6%E5%B9%B6%E5%9C%A8%E6%9C%80%E5%90%8E%E4%B8%A4%E4%B8%AA%E5%BC%95%E7%94%A8%E4%B9%8B%E9%97%B4%E6%B7%BB%E5%8A%A0%E2%80%9Cand%E2%80%9D%EF%BC%9F.png)
\citeauthor{iso9241-5,ansi2007,osha3092}
生产
国际标准化组织;人因与人体工程学学会;职业安全与健康管理局
是否有一个漂亮的命令可以使其产生
国际标准化组织、人因与人体工程学学会和职业安全与健康管理局
所以我不必写
\citeauthor{iso9241-5}, \citeauthor{ansi2007} and \citeauthor{osha3092}
答案1
natbib
要格式化包中的标点符号,请使用以下命令\setcitestyle
: 引用之间的字符可以按以下方式设置:
\setcitestyle{comma}
等于
\setcitestyle{citesep={,}}
这里有一个可以做你想做的事情的例子:(可能存在错误)
\documentclass{book}
\usepackage{lipsum}
\usepackage{natbib}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{test,
author={John Smith},
title={TITLE},
year={2011},
publisher={...},
}
@book{test1,
author={Theodor Fontane},
title={Zaubefloete},
year={1000},
publisher={...},
}
@book{test2,
author={Wolfgang Goethe},
title={Irgendwas},
year={1000},
publisher={...},
}
\end{filecontents*}
\makeatletter
\newcount\nat@length@list
\newcount\nat@tempcount
\renewcommand\NAT@sort@cites[1]{%
\let\NAT@cite@list\@empty
\nat@length@list=0%
\@for\@citeb:=#1\do{%
\global\advance\nat@length@list\@ne%
\expandafter\NAT@star@cite\@citeb\@@}%
\if@filesw
\expandafter\immediate\expandafter\write\expandafter\@auxout
\expandafter{\expandafter\string\expandafter\citation\expandafter{\NAT@cite@list}}%
\fi
\@ifnum{\NAT@sort>\z@}{%
\expandafter\NAT@sort@cites@\expandafter{\NAT@cite@list}%
}{}%
}%
%
\def\NAT@def@citea@close{%
\def\@citea{%
\NAT@@close%
\ifnum\nat@length@list=2
\NAT@space and\NAT@space%
\else
\NAT@separator\NAT@space%
\fi
\advance\nat@length@list-\@ne%
}%
}
\makeatother
\begin{document}
\citeauthor{test,test1,test2}
\bibliography{\jobname.bib}
\bibliographystyle{plainnat}
\end{document}
答案2
这是一个可能的解决方案;我没有修改命令,而是\citeauthor
定义了一个新\CiteList
命令来执行您想要的操作:它采用逗号分隔的书目键列表并调用\citeauthor
每个元素,使用\MidSep
(最初定义为逗号后跟一个空格)作为分隔符,但最后两个元素除外,它们将使用\LastSep
(最初定义为空格包围的单词“and”)分隔。重新定义后\LastSep
,\MidSep
您可以轻松自定义样式:
\begin{filecontents*}{mybiblio.bib}
@book{goossens93,
author = "Michel Goossens and Frank Mittlebach and Alexander Samarin",
title = "The {LaTeX} Companion",
year = "1993",
publisher = "Addison-Wesley",
address = "Reading, Massachusetts"
}
@book{knuth84,
author = "Donald E. Knuth",
title= "The {TeX}book",
publisher = "Addison-Wesley",
year = 1984
}
@unpublished{patashnik88,
author = "Oren Patashnik",
title = "Using {BibTeX}",
note = "Documentation for general BibTeX users",
month = jan,
year = 1988
}
\end{filecontents*}
\documentclass{article}
\usepackage{natbib}
\makeatletter
\newcommand\MidSep{, }% separator for two elements, not the last two
\newcommand\LastSep{ and }% separator for last two elements
\newcommand\CiteList[1]{%
\let\last@elem\relax
\let\last@sep\relax
\@for\@list:=#1\do{%
\ifx\last@elem\relax\else
\ifx\last@sep\relax
\def\last@sep{\LastSep}% the separator between the last two elements should is "and"
\else\MidSep % the separator between two elements (not the two last) is a comma
\fi
\citeauthor{\last@elem}%
\fi
\let\last@elem\@list
}% the last element of the list:
\ifx\last@elem\relax\else
\last@sep\citeauthor{\last@elem}%
\fi
}
\makeatother
\begin{document}
\CiteList{goossens93,knuth84,patashnik88}
\renewcommand\LastSep{/}
\renewcommand\MidSep{/}
\CiteList{goossens93,knuth84,patashnik88}
\bibliographystyle{plainnat}
\bibliography{mybiblio}
\end{document}
答案3
在 中natbib
,为了强制引用(例如,通过 创建\citeauthor
)之间的分隔符为逗号而不是分号,您可以在序言中输入以下内容(加载 natbib 包后):
\setcitestyle{citesep={,}}
但是,这种更改不会在列表的倒数第二项和最后一项之间插入一个漂亮的“and”,而这正是您想要的,对吗?我想您必须输入\citeauthor{iso9241-5, ansi2007} and \citeauthor{osha3092}
。这与您最初的想法相比并没有太大的改进,但至少是朝着正确方向迈出的一小步……
答案4
这是一个受 Marco 和 Mico 更优雅的方法启发的 hack,它提供了 \citeauthors 命令而无需使用 TeX 原语。
\setcitestyle{comma}
\newcommand\citeauthors[2]{\citeauthor#1 and \citeauthor#2}
\citeauthors{john,paul,george}{ringo}
但马可仍然获胜。