# Show Equation number in colored box without brackets

In the attached code, I would like to get the equation number to show up boxed like this:

instead of the normal brackets "()".

Here is my MWE:

\documentclass[11pt,fleqn]{book}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{amsmath,amsfonts,amssymb,amsthm}

\usepackage[most]{tcolorbox}
\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}
\tcbset{myformula/.style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=ocre,
boxrule=0.8pt,
left=2pt,
right=2pt,
highlight math style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=red.
}
}
}

}{%
\ignorespacesafterend
}

\begin{document}
\chapter{This is how it all began}
\section{Introduction}

\begin{tcolorbox}[ams align,myformula]
LT~&\approx~\frac{400}{F_{c}}(1-log_{10}|\Delta F|)\\
\Delta F~&=~\frac{Frequency~Tolerance}{Frequency~Jump}\nonumber
\end{tcolorbox}

\end{document}


You can redefine the internal \tagform@; the original definition is

\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}


and I used a \fcolorbox:

\makeatletter
\def\tagform@#1{\fcolorbox{ocre}{mygray}{\maketag@@@{\ignorespaces\textcolor{ocre}{#1}\unskip\@@italiccorr}}}
\makeatother


The complete code:

\documentclass[11pt,fleqn]{book}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{amsmath,amsfonts,amssymb,amsthm}

\usepackage[most]{tcolorbox}
\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\tcbset{myformula/.style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=ocre,
boxrule=0.8pt,
left=2pt,
right=2pt,
highlight math style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=red.
}
},
}

}{%
\ignorespacesafterend
}

\makeatletter
\def\tagform@#1{\fcolorbox{ocre}{mygray}{\maketag@@@{\ignorespaces\textcolor{ocre}{#1}\unskip\@@italiccorr}}}
\makeatother

\begin{document}
\chapter{This is how it all began}
\section{Introduction}

A cross-reference using \verb!\ref!: \ref{equ:test}\par\noindent
A cross-reference using \verb!\eqref!: \eqref{equ:test}
\begin{tcolorbox}[ams align,myformula]
LT~&\approx~\frac{400}{F_{c}}(1-log_{10}|\Delta F|) \label{equ:test}\\
\Delta F~&=~\frac{Frequency~Tolerance}{Frequency~Jump}\nonumber
\end{tcolorbox}

\end{document}


• I didn't realize that you posted, so I have deleted my (duplicate) answer. I apparently used your nice solution at tex.stackexchange.com/questions/122177/…. +1 – Steven B. Segletes Sep 8 '15 at 18:12
• how do you give a cross-reference to such an equation? (neither \ref not \eqref seems to work, but that could be because i don't have easy access to the latest versions of all the packages.) would be helpful if you added an example. – barbara beeton Sep 8 '15 at 18:26
• @barbarabeeton both \ref and \eqref work. The latter will produce the reference in a frame like the one used for the tags. I'll add an example. – Gonzalo Medina Sep 8 '15 at 18:28
• @barbarabeeton I spoke too soon! \eqref produced the proper refeernce inside the framed box but on a new line, so now I changed to a simple \fcolorbox which gives better results for \eqref. I updated the code with an example of cross-references. – Gonzalo Medina Sep 8 '15 at 18:38
• @Joe You're welcome. Due to a little problem with \eqref using the \tcbox approach I changed the code to use nos a \fcolorbox which behaves as expected. Please see the updated answer. – Gonzalo Medina Sep 8 '15 at 18:39

Here is a simple solution with mathtools and its \newtagform command:

\documentclass[11pt,fleqn]{book}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{mathtools,amsfonts,amssymb,amsthm}
\newtagform{boxed}[\fboxrule=0.6pt\fcolorbox{ocre}{ocre!15!}]{\color{ocre}}{}
\usepackage[most]{tcolorbox}
\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}
\tcbset{myformula/.style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=ocre,
boxrule=0.8pt,
left=2pt,
right=2pt,
highlight math style={
arc=0pt,
outer arc=0pt,
colback=mygray,
colframe=red.
}
}
}

}{%
\ignorespacesafterend
}

\begin{document}
\chapter{This is how it all began}
\section{Introduction}
\usetagform{boxed}
\begin{tcolorbox}[ams align,myformula]
LT~&\approx~\frac{400}{F_{c}}(1-log_{10}|\Delta F|)\label{coloureq}\\
\Delta F~&=~\frac{Frequency~Tolerance}{Frequency~Jump}\nonumber
\end{tcolorbox}

\ref{coloureq}

\eqref{coloureq}

\end{document}


• can you extend the example to show how \ref and \eqref` would be used? – barbara beeton Sep 8 '15 at 19:30
• @barbara beeton: Done, milady! – Bernard Sep 8 '15 at 19:47
• With this approach, how would you change the color of the equation number text to ocre in the equation environment? – Joe Sep 8 '15 at 20:03
• In the first pair of empty braces (where usually one puts an opening bracket or parenthesis). See my updated answer. – Bernard Sep 8 '15 at 20:10
• You're welcome. 'Twas a pleasure to help. – Bernard Sep 8 '15 at 20:32