修改 \citet* 的渲染

修改 \citet* 的渲染

我想更改\citet*使用較小字體大小和某種顏色的渲染。

下面的 MWE 適用於未加星號的版本\citet並產生

在此輸入影像描述

\documentclass{article}

\usepackage{filecontents}
\usepackage{natbib}
\usepackage{color}

\let\oldcitet=\citet
\renewcommand{\citet}[1]{{\footnotesize\textcolor[rgb]{.8, .1, .4}{\oldcitet{#1}}}}

\begin{filecontents}{refs.bib}
@book{ref,
title = {title},
author = {john and abi and fein},
location = {here},
publisher = {publisher},
year = {2017},
}
\end{filecontents}

\begin{document}

\citet{ref}

\citet*{ref}

\bibliography{refs.bib}

\bibliographystyle{plainnat}

\end{document}

的重新定義\citet打破了其加星號版本的定義。對於如何解決這個問題,有任何的建議嗎?

答案1

為了在您的設定中容納加星號的版本,您需要限制使用*以下內容的使用:

\let\oldcitet=\citet
\makeatletter
\renewcommand{\citet}{\@ifstar\newcitetstar\newcitet}
\newcommand{\newcitet}[1]{{\footnotesize\textcolor[rgb]{.8, .1, .4}{\oldcitet{#1}}}}
\newcommand{\newcitetstar}[1]{{\footnotesize\textcolor[rgb]{.8, .1, .4}{\oldcitet*{#1}}}}
\makeatother

在此輸入影像描述

還有更簡單的方法來協商其他選項,例如可選參數(例如)。對於更通用的方法,我會考慮xparse

相關內容