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?
Asked
Active
Viewed 6,289 times
12
2 Answers
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}

Moriambar
- 11,466
Thomas F. Sturm
- 25,210
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}

Moriambar
- 11,466
-
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 Sep 25 '13 at 12:30
-
@Pygmalion My first like is
tcolorboxas it is more fancier. But don't ignoreempheqtoo as it has some good features. – Sep 25 '13 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 Sep 25 '13 at 12:51
-
@Pygmalion That is what I meant in my previous comment. But
empheqsaves you there :) – Sep 25 '13 at 12:52 -
Indeed, but are you sure that empheq can create exactly the same frame style as tcolorbox? – Pygmalion Sep 25 '13 at 13:17
-
@pygmalion I am skeptical about that. tcolorbox can get way more fancier than empheq. – Sep 25 '13 at 13:21
-
@Pygmalion You can combine
empheqandtcolorboxto frame multiple equations without equation numbers :-) I added an answer to show how to do this. – Thomas F. Sturm Sep 26 '13 at 08:44
empheqpackage. – egreg Sep 25 '13 at 09:53