带有 cref 的方程式使用不同颜色

带有 cref 的方程式使用不同颜色

我正在处理一些方程式,并希望它们的超链接颜色与我在 中设置的其他链接颜色不同\hypersetup。现在,似乎邮政如果不是排除等式 ()链接的一部分仍然保持着原来设置的颜色\hypersetup

有没有办法让整个文本变成青色(或任何其他颜色)?提前致谢,下面是 MWE 和相关输出:

\documentclass[12pt]{report}


\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{float}

\usepackage{hyperref}

\hypersetup{
    colorlinks,
    citecolor=electricultramarine,
    filecolor=.,
    linkcolor=maroon,
    urlcolor=smokyblack,
    linktoc=all
}
\definecolor{teal}{rgb}{0.0, 0.5, 0.5}
\definecolor{cobalt}{rgb}{0.0, 0.28, 0.67}
\definecolor{maroon}{rgb}{0.69, 0.19, 0.38}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\definecolor{lightgray}{rgb}{0.83, 0.83, 0.83}
\definecolor{smokyblack}{rgb}{0.06, 0.05, 0.03}
\definecolor{ceruleanblue}{rgb}{0.16, 0.32, 0.75}
\definecolor{electricultramarine}{rgb}{0.25, 0.0, 1.0}

\usepackage[noabbrev,nameinlink]{cleveref}
\crefname{subsection}{subsection}{subsections}
\creflabelformat{equation}{#2\textup{(\textcolor{teal}{#1})}#3}

\begin{document}
\chapter{Methods}
\dots
\section{Population genetics and Demographic Inference}
\dots
\subsection{PCA and other exploratory population genetic analyses} \label{exploratory}

This is the method subsection for exploratory analyses.

\chapter{Results}
\dots
\section{Exploratory population genetics analyses}

\dots This value, known as Watterson estimator (or $\theta$ Watterson) <citation>, is expressed by the following equation with the number of polymorphic sites set as K:
\begin{equation} \label{equation:1}
\widehat{\theta}_w = \frac{K}{a_n} \text{, with } a_n = \sum_{i=1}^{n-1} \frac{1}{i}
\end{equation}

When I use a normal \texttt{cleveref} I get the expected output in: \textbf{\Cref{exploratory}}; on the other hand, even following the example in the post, I cannot get rid of the maroon hyperlink color for the equation and brackets part of the text when linking an equation: \textbf{\cref{equation:1}}.

\end{document}

在此处输入图片描述

答案1

使用\crefformat带有前缀的完整引用而不仅仅是标签:

\documentclass[12pt]{report}

\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{float}

\usepackage{hyperref}

\hypersetup{
    colorlinks,
    citecolor=electricultramarine,
    filecolor=.,
    linkcolor=maroon,
    urlcolor=smokyblack,
    linktoc=all
}
\definecolor{teal}{rgb}{0.0, 0.5, 0.5}
\definecolor{cobalt}{rgb}{0.0, 0.28, 0.67}
\definecolor{maroon}{rgb}{0.69, 0.19, 0.38}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\definecolor{lightgray}{rgb}{0.83, 0.83, 0.83}
\definecolor{smokyblack}{rgb}{0.06, 0.05, 0.03}
\definecolor{ceruleanblue}{rgb}{0.16, 0.32, 0.75}
\definecolor{electricultramarine}{rgb}{0.25, 0.0, 1.0}

\usepackage[noabbrev,nameinlink]{cleveref}
\crefname{subsection}{subsection}{subsections}
\crefformat{equation}{\textcolor{teal}{equation~#2\textcolor{teal}{(#1)}#3}}

\begin{document}
\chapter{Methods}
\dots
\section{Population genetics and Demographic Inference}
\dots
\subsection{PCA and other exploratory population genetic analyses} \label{exploratory}

This is the method subsection for exploratory analyses.

\chapter{Results}
\dots
\section{Exploratory population genetics analyses}

\dots This value, known as Watterson estimator (or $\theta$ Watterson) <citation>, is expressed by the following equation with the number of polymorphic sites set as K:
\begin{equation} \label{equation:1}
\widehat{\theta}_w = \frac{K}{a_n} \text{, with } a_n = \sum_{i=1}^{n-1} \frac{1}{i}
\end{equation}

When I use a normal \texttt{cleveref} I get the expected output in: \textbf{\Cref{exploratory}}; o[![enter image description here][1]][1]n the other hand, even following the example in the post, I cannot get rid of the maroon hyperlink color for the equation and brackets part of the text when linking an equation: \textbf{\cref{equation:1}}.

\end{document}

在此处输入图片描述

外部\textcolor会改变一般颜色,但这会被和hyperref生成的链接覆盖。要再次更改该颜色,还需要内部的和之间。前缀和链接之间有一个不可中断的空格。#2#3\textcolor#2#3~

如果您希望前缀成为链接的一部分,您可以使用:

\crefformat{equation}{#2\textcolor{teal}{equation~(#1)}#3}

cleveref有关工作原理的更多信息,请参阅手册\crefformat

相关内容