12

I am in the process of finalizing the notebook text, and I am into framing equations and figures. For this I am testing mdframed package, which produces nice frames. However, I don't know how to frame only equations, without framing equation numbers. Is that possible in mdframed?

1
  • 2
    For framing equations you should have a look at the empheq package.
    – egreg
    Commented Sep 25, 2013 at 9:53

2 Answers 2

18

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}

enter image description here

0
9
\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}

enter image description here

7
  • Interesting stuff. Since you are obviously knowledgeable in this area, which package in your opinion is the best for my use - I am writing a book, and I need frames around formulas, pictures, occasionally text etc.
    – Pygmalion
    Commented Sep 25, 2013 at 12:30
  • @Pygmalion My first like is tcolorbox as it is more fancier. But don't ignore empheq too as it has some good features.
    – user11232
    Commented Sep 25, 2013 at 12:32
  • tcolorbox looks tempting, but I have just found out it does not support frames around align environment (multiple equations within frame without equation numbers)
    – Pygmalion
    Commented Sep 25, 2013 at 12:51
  • @Pygmalion That is what I meant in my previous comment. But empheq saves you there :)
    – user11232
    Commented Sep 25, 2013 at 12:52
  • Indeed, but are you sure that empheq can create exactly the same frame style as tcolorbox?
    – Pygmalion
    Commented Sep 25, 2013 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .