Putting frame only around equation using mdframed package
To supplement the answer of Harish Kumar, the packages empheq
and tcolorbox
can by used in symbiosis. empheq
allows to specify any box to mark the given equations. For the box you may insert any tcolorbox
which behaves like fbox
. Typically, such boxes are based on the \tcbox
macro (like \tcbhighmath
in the answer of Harish Kumar).
I think, the following example demonstrates what you can do. The singleline equation is boxed with \tcbhighmath
directly, the multiline equations (align
) are boxed using empheq
in conjunction with \tcbhighmath
and some other \tcbox
-based examples.
\documentclass{article}
\usepackage[svgnames,hyperref]{xcolor}
\usepackage{empheq}
\usepackage[many]{tcolorbox}
\tcbset{highlight math style={enhanced,
colframe=red!60!black,colback=yellow!50!white,arc=4pt,boxrule=1pt,
drop fuzzy shadow}}
\newtcbox{\otherbox}[1][]{nobeforeafter,math upper,tcbox raise base,
enhanced,frame hidden,boxrule=0pt,interior style={top color=green!10!white,
bottom color=green!10!white,middle color=green!50!yellow},
fuzzy halo=1pt with green,#1}
\newtcbox{\picturebox}[1][]{nobeforeafter,math upper,tcbox raise base,
enhanced,watermark graphics=example-grid-100x100bp.jpg,% from package mwe
colback=white,frame hidden,boxrule=0pt,arc=10pt,
watermark stretch=1.00,watermark opacity=0.4,#1}
\begin{document}
\begin{equation}
\tcbhighmath{E = mc^2}
\end{equation}
\begin{empheq}[box=\tcbhighmath]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\begin{empheq}[box={\tcbhighmath[colback=blue!20!white]}]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\begin{empheq}[box={\tcbhighmath[watermark text=?!,watermark color=yellow!90!red]}]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\begin{empheq}[box=\otherbox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\begin{empheq}[box=\picturebox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\end{document}
\documentclass{article}
\usepackage{mathtools}
\usepackage{empheq}
%\usepackage{xcolor}
\usepackage[skins,theorems]{tcolorbox}
\tcbset{highlight math style={enhanced,
colframe=red!60!black,colback=white,arc=4pt,boxrule=1pt}}
\definecolor{myblue}{rgb}{.8, .7, 1}
\newcommand*\mybluebox[1]{%
\colorbox{myblue}{\hspace{1em}#1\hspace{1em}}}
\begin{document}
Using \verb|tcolorbox|:
\begin{equation}
\tcbhighmath{E = mc^2}
\end{equation}
Using \verb|Aboxed| from \verb|mathtools|:
\begin{align}
\Aboxed{E &= mc^2}
\end{align}
Using \verb|empheq| (taken from manual):
\begin{empheq}[box=\fbox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
Adding some color (taken from manual):
\begin{empheq}[box=\mybluebox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}
\end{document}