如何改变方程式数字的颜色?

如何改变方程式数字的颜色?

我想将部分文本设置为不同的颜色。我对方程式有疑问,因为方程式数字仍然是黑色的。例如:

\documentclass{article}
\usepackage{color}

\begin{document}

This text is written in black and the equations too:
\begin{equation}
  \cos^2\theta + \sin^2\theta = 1
\end{equation}
\begin{eqnarray}
  \textrm{e}^{i\theta} = \cos\theta + i\sin\theta
\end{eqnarray}

\color{red}
Now we write in red, but the equation numbers are still in black!
\begin{equation}
  \cos^2\theta + \sin^2\theta = 1
\end{equation}
\begin{equation}
  \textrm{e}^{i\theta} = \cos\theta + i\sin\theta
\end{equation}

\end{document}

答案1

正如@campa 在评论中指出的那样,如果amsmath加载了该包,您的格式化目标就会自动实现。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,xcolor}
\begin{document}
This text is written in black and the equations too:
\begin{gather}
  \cos^2\theta + \sin^2\theta = 1 \\
  \mathrm{e}^{i\theta} = \cos\theta + i\sin\theta
\end{gather}

\color{red}
Now we write in red, and the equation numbers are also in red.
\begin{gather}
  \cos^2\theta + \sin^2\theta = 1 \\
  \mathrm{e}^{i\theta} = \cos\theta + i\sin\theta
\end{gather}
\end{document}

答案2

没有 的解amsmath。我们必须\normalcolor在 的定义中删除\@eqnnum。我已添加\color{red}来代替它,但您也可以省略它,以使方程编号受到影响而发生\color变化。

\documentclass{article}
\usepackage{color}

\makeatletter
\def\@eqnnum{{\normalfont \color{red} (\theequation)}}% \normalcolor deleted, \color{...} added
\makeatother

\begin{document}

\begin{equation}
  \cos^2\theta + \sin^2\theta = 1
\end{equation}
\begin{equation}
  \textrm{e}^{i\theta} = \cos\theta + i\sin\theta
\end{equation}

\end{document}

在此处输入图片描述

答案3

重新定义 tagform@

\documentclass{article}
\usepackage{xcolor,amsmath}

\makeatletter
\def\tagform@#1{\maketag@@@{\color{red}(\ignorespaces#1\unskip\@@italiccorr)}}
\makeatother

\begin{document}

\begin{equation}
  \cos^2\theta + \sin^2\theta = 1
\end{equation}

\end{document}

相关内容