cleveref 的问题

cleveref 的问题

我想给我的定理和问题上色。我使用以下代码:

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[breaklinks,colorlinks,pagebackref]{hyperref} 
\hypersetup{linkcolor=Red , citecolor=Green}
\usepackage[capitalise,nameinlink]{cleveref}
\newtheorem{theorem}{\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue} Question }
\begin{document}
\begin{question}\label{qu1}  Question 1
\end{question}

\begin{theorem}\label{thm1} Theorem 1
\end{theorem}
Now we reference to ~\cref{thm1} and ~\cref{qu1}.

\end{document}

通过运行这个,我收到以下错误消息:

\@declaredcolor 的参数有一个额外的 }。”

我不知道问题出在哪里。你能看出问题所在吗?

谢谢

答案1

\color是一个“脆弱的”(在 LaTeX 特定意义上)命令。您需要更改

\newtheorem{theorem}{\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue} Question }

\newtheorem{theorem}{\protect\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\protect\color{Blue} Question }

甚至更好,如下所示egreg 的回答,就是在和计数器\crefname上(重新)运行。这是一个 MWE(最小工作示例):theoremquestion

在此处输入图片描述

\documentclass{amsart} % loads 'amsthm' package automatically

\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,linkcolor=Red]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\newtheorem{theorem}{\color{Blue}Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue}Question}
\crefname{theorem}{Theorem}{Theorems} % thanks, @egreg!
\crefname{question}{Question}{Questions}

\begin{document}
\setcounter{section}{2} % just for this example

\begin{question}\label{qu1}Question 1\end{question}
\begin{theorem}\label{thm1}Theorem 1\end{theorem}
\noindent
Now we cross-reference~\cref{thm1,qu1}.
\end{document}

答案2

您必须删除以下颜色规范\cref

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,pagebackref]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\hypersetup{linkcolor=Red , citecolor=Green}

\newtheorem{theorem}{\textcolor{Blue}{Theorem}}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\textcolor{Blue}{Question}}

\crefname{theorem}{Theorem}{Theorems}
\crefname{question}{Question}{Questions}

\begin{document}

\begin{question}\label{qu1}
Question 1
\end{question}

\begin{theorem}\label{thm1}
Theorem 1
\end{theorem}

Now we reference to~\cref{thm1} and~\cref{qu1}.

\end{document}

在此处输入图片描述

好的,这个数字没有变色。由于 Mico 窃取了我的代码,所以这里有一个更好的。

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,pagebackref]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\hypersetup{linkcolor=Red , citecolor=Green}

% see https://tex.stackexchange.com/a/17555/4427
\newtheoremstyle{colorplain}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\itshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\color{Blue}\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}          % CUSTOM-HEAD-SPEC
\newtheoremstyle{colordefinition}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\normalfont}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\color{Blue}\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}          % CUSTOM-HEAD-SPEC

\theoremstyle{colorplain}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{colordefinition}
\newtheorem{question}[theorem]{Question}

\begin{document}

\begin{question}\label{qu1}
Question 1
\end{question}

\begin{theorem}\label{thm1}
Theorem 1
\end{theorem}

Now we reference to~\cref{thm1} and~\cref{qu1}.

\end{document}

在此处输入图片描述

相关内容