# Coloured box around equation in tabular

I have been using the empheq package to put coloured boxes around some equations. I tried to put it inside a tabular environment and it flags up the following errors:

Bad math environment delimiter. \end{empheq}}
\begin{equation*} on input line 25 ended by \end{AmSequation*}. \end{empheq}}


The document compiles fine with no errors when the empheq environment is placed outside of the tabular environment, but when included in the multicolumn it gives the two above errors (although it does print the correct result).

What is causing the two errors when the boxed equation is placed inside the tabular environment?

Here is a minimal working example:

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{empheq}
\usepackage{float}

\newtcbox{\mymath}[1][]{%
nobeforeafter, math upper, tcbox raise base,
enhanced, colframe=blue!30!black,
colback=blue!30, boxrule=1pt,
#1}

\begin{document}

\begin{tabular}{c|c}
\multicolumn{2}{c}{
\begin{empheq}[box=\mymath]{equation*}
\int_{-y}^{y} f(x) dx
\end{empheq}}\\ \\
\hline
\textbf{Lower limit} & \textbf{Upper limit} \\
\hline
-y & y \\
\end{tabular}

\end{document}


Here is the output:

Any help is greatly appreciated.

-Yeti

I think your problem arises from essentially putting an equation environment inside a table. (Although just putting a non-empheq equation environment inside the table gives a different error, it still won't work).

The point of using empheq is to allow AMS equation numbering outside the emphasizing tcolorbox. If you don't need the numbering and centering/spacing that comes with the AMS display environments, you can just use your defined tcolorbox on its own without empheq:

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{empheq}
\usepackage{float}

\newtcbox{\mymath}[1][]{%
nobeforeafter, math upper, tcbox raise base,
enhanced, colframe=blue!30!black,
colback=blue!30, boxrule=1pt,
#1}

\begin{document}

\begin{tabular}{c|c}
\multicolumn{2}{c}{
\mymath{\int_{-y}^{y} f(x) dx}
}\\ \\
\hline
\textbf{Lower limit} & \textbf{Upper limit} \\
\hline
-y & y \\
\end{tabular}

\end{document}

• Thank you for the fix, it makes sense now why it was not working. – Yeti Dec 5 '16 at 9:24

empheq cannot be used in tabular cell, unless it's declared as p, which you don't really need; just use \mymath.

However, in this case the tcbox raise base option should be nullified, so we can better control the vertical spacing. This can be done with tcbox raise=0mm.

I also improved the appearance of the table with booktabs rules, avoiding the vertical rule that serves no purpose.

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}

\newtcbox{\mymath}[1][]{%
on line, % does 'nobeforeafter' and 'tcbox raise base'
math upper,
enhanced,
colframe=blue!30!black,
colback=blue!30,
boxrule=1pt,
#1
}

\begin{document}

\begin{tabular}{cc}
\multicolumn{2}{c}{%
\mymath[tcbox raise=0mm]{% we don't want on line, in this case
\int_{-y}^{y} f(x) \,dx
}%
}
\\
\midrule[\heavyrulewidth]
Lower limit & Upper limit \\
\cmidrule(lr){1-1}\cmidrule(lr){2-2}
$-y$ & $y$ \\
\bottomrule
\end{tabular}

\end{document}