My solution is a little more unusual, but in the end it lets you keep the equation numbering and lets you highlight the box containing the equation.
To achieve that I defined a \newcommand
which I called \fancyboxed
which has the following synopsis:
\fancyboxed[<background color>]{<equation>}
Please note that in this case the argument <equation>
is already in math mode, so you don't have to insert things such as $...$
, \[...\]
, etc.
The basic idea behind my solution was to treat the equation as the argument of a (rectangular) tikz node spanning the entire \linewidth
.
Here is the code:
\documentclass{article}
\usepackage{tikz} %drawing
\usepackage{amsmath}
\usepackage{lipsum} %dummy text
\newcommand{\fancyboxed}[2][white]{ %white is default background
\begin{equation}
\tikz \node at(0,0) [shape=rectangle,draw,thick,minimum width=\linewidth,fill=#1] {$\displaystyle #2$};
\end{equation}
}
\begin{document}
\lipsum[1]
\fancyboxed{p(v,h) = \frac{1}{Z} e ^{-E(v,h)}}
\fancyboxed[red!30]{p(v,h) = \frac{1}{Z} e ^{-E(v,h)}}
\lipsum[2]
\end{document}
