# Boxed equation with equation number inside

I have a question that seems to not been answered directly, i tried using the empheq package to make boxes around equation (in the align environment ) and it works, but i want a wide box which occupies the hole textwidth and includes the equation number.

Here is an example code:

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{xcolor}
\empheqset{box=\fcolorbox{white}[gray]{0.85}}

\begin{document}

\begin{empheq}{align}
U_e(r_A)=&-\frac{\hbar\mu_0}{8\pi^2c}\int\limits_0^\infty d\xi\xi^3\alpha(i\xi)\sum\limits_{l=1}^{\infty}(2l+1)\bigg\{r_{lTE}[h^{(1)}_l(kr_A)]^2\nonumber\\
&+r_{lTM}\bigg[l(l+1)\frac{[h^{(1)}_l(kr_A)]^2}{(kr_A)^2}+\frac{[kr_Ah^{(1)}_l(kr_A)]'^2}{(kr_A)^2}\bigg]
\bigg\}
\end{empheq}

\end{document}


• Might be better to use mdframed for such things. – daleif Nov 5 '14 at 9:32

A tcolorbox solution:

\documentclass[]{article}
\usepackage{amsmath}

\usepackage[most]{tcolorbox}

\newtcolorbox{empheqboxed}{colback=gray!35,
colframe=white,
width=\textwidth,
sharpish corners,
top=-2mm, % default value 2mm
bottom=0pt
}

\begin{document}

\begin{empheqboxed}%
\begin{align}
U_e(r_A)=&-\frac{\hbar\mu_0}{8\pi^2c}\int\limits_0^\infty d\xi\xi^3\alpha(i\xi)\sum\limits_{l=1}^{\infty}(2l+1)\bigg\{r_{lTE}[h^{(1)}_l(kr_A)]^2\nonumber\\
&+r_{lTM}\bigg[l(l+1)\frac{[h^{(1)}_l(kr_A)]^2}{(kr_A)^2}+\frac{[kr_Ah^{(1)}_l(kr_A)]'^2}{(kr_A)^2}\bigg]
\bigg\}
\end{align}
\end{empheqboxed}

\end{document}


The result:

• Wow that was fast, thank you! May I ask if there is a possibily to adjust the border at the top and the bottom, at the top there is way to much "free space". – Josh Nov 5 '14 at 9:40
• @Josh: Sure, you can play with top and bottom keys. To customize more, you can further change the values. – Claudio Fiandrino Nov 5 '14 at 9:48
• Tank you so much for the quick reply! – Josh Nov 5 '14 at 9:53

Another tcolorbox solution. tcolorbox supports ams environments well.

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{showframe}   %% for demo
\usepackage{empheq}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={colback=gray!40,colframe=green!50!black,
every box/.style={highlight math style={colback=LightBlue!50!white,colframe=Navy}}
}}

\begin{document}
\begin{tcolorbox}[ams align,myformula]
U_e(r_A) &=-\frac{\hbar\mu_0}{8\pi^2c}\int\limits_0^\infty d\xi\xi^3\alpha(i\xi)\sum\limits_{l=1}^{\infty}(2l+1)\bigg\{r_{lTE}[h^{(1)}_l(kr_A)]^2\nonumber\\
&\phantom{{}=}{}+{}r_{lTM}\bigg[l(l+1)\frac{[h^{(1)}_l(kr_A)]^2}{(kr_A)^2}+\frac{[kr_Ah^{(1)}_l(kr_A)]'^2}{(kr_A)^2}\bigg]
\bigg\}
\end{tcolorbox}

\end{document}


• This one looks very good, i really like how the spacing on the top and bottom side result, thank you! – Josh Nov 5 '14 at 10:33
• what is kinda odd, is that the math environment, at leat for me (using TexStudio) is gone, so i loose autocompletation. – Josh Nov 5 '14 at 10:39