citeauthor 和 cite 命令的不同链接颜色

citeauthor 和 cite 命令的不同链接颜色

这个问题显然与这个,作者并未继续提供可行的示例。

我想将\citeauthor链接的颜色设为黑色,将 的颜色\cite设为蓝色。在下面的例子中,作者和引用编号均为蓝色,而 显然没有关键字citeauthorcolorhyperref我该如何制作不同的颜色?

主文本

\documentclass[12pt]{article}

\usepackage[colorlinks=true, citecolor=blue]{hyperref}
\usepackage[numbers]{natbib}

\begin{document}

The work by \citeauthor{myref} was a fancy read~\cite{myref}.

\bibliographystyle{plainnat}
\bibliography{main}

\end{document}

主目录

@article{myref,
    title = {Fancy title},
    journal = {Journal of Fancy Publications},
    author = {Jane Dee and John Doe},
    year = {2017},
    pages = {293--311},
}

编译:pdflatex main; bibtex main; pdflatex main; pdflatex main;

答案1

这是一个“黑客”行为:

\documentclass[12pt]{article}

\usepackage[colorlinks=true, citecolor=blue]{hyperref}
\usepackage[numbers]{natbib}
\usepackage{filecontents}

\let\oldciteauthor=\citeauthor
\def\citeauthor#1{\hypersetup{citecolor=blue}\oldciteauthor{#1}}
\let\oldcite=\cite
\def\cite#1{\hypersetup{citecolor=red}\oldcite{#1}}
\begin{filecontents}{main.bib}
@article{myref,
    title = {Fancy title},
    journal = {Journal of Fancy Publications},
    author = {Jane Dee and John Doe},
    year = {2017},
    pages = {293--311},
}
\end{filecontents}

\begin{document}

The work by \citeauthor{myref} was a fancy read~\cite{myref}.

\bibliographystyle{plainnat}
\bibliography{main}

\end{document}

输出:

在此处输入图片描述

相关内容