3

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}

The provided code returns this result

Josh
  • 512

2 Answers2

4

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:

enter image description here

2

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}

enter image description here

  • This one looks very good, i really like how the spacing on the top and bottom side result, thank you! – Josh Nov 05 '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 05 '14 at 10:39