# How to color a tag in a math equation?

I have a math equation with a \tag operator.

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

\begin{document}

This is my favorite equality:
\begin{align*}
\color{red}\sum_{n=1}^\infty\dfrac{1}{n^2}=\dfrac{\pi^2}{6}.\tag{E1}
\end{align*}

\end{document}


I would like to color the tag (E1) in red.

What I did is I added \tag{\textcolor{red}{E1}} but this only colored the E1 without the parentheses.

• You could use \tag* and add the () manually to it – daleif Jul 17 at 11:18
• You could write either \tag*{\textcolor{red}{(E1)}} (as already suggested by @daleif) or \tag*{\color{red}(E1)}. – Mico Jul 17 at 11:28

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

\usepackage{mathtools}
\usepackage{xcolor}
\newtagform{red}{\color{red}(}{)}
\usetagform{red}
\begin{document}

\begin{align*}
\color{red} \sum_{n=1}^\infty\dfrac{1}{n^2}=\dfrac{\pi^2}{6}.\tag{E1}
\end{align*}

\end{document}


You can redefine the tag

Hope this helps!

CODE with newcommand

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor}
\newcommand{\TAG}[1]{\tag*{\textcolor{red}{(#1)}}}
\begin{document}

This is my favorite equality:
\begin{align*}
\color{red}\sum_{n=1}^\infty\dfrac{1}{n^2}=\dfrac{\pi^2}{6}.\TAG{E1}
\end{align*}

\end{document}


CODE based on the comments by daleif and Mico

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

\begin{document}

This is my favorite equality:
\begin{align*}
\color{red}\sum_{n=1}^\infty\dfrac{1}{n^2}=\dfrac{\pi^2}{6}.
\tag*{\textcolor{red}{(E1)}}
\end{align*}

\end{document}

• Approved all the answers and the question. – Sebastiano Jul 17 at 12:13