21

When I want to highlight some important result, I traditionnally put my equations in boxes:

\begin{equation}
boxed{\Delta = b^2-4ac}
\end{equation}

I would like to have a more fancy thing:

  • to be able to set the thickness and the color of the line of the box
  • to be able to add a coloured shadow under this box

to obtain this kind of result:

enter image description here

I asked the same kind of question a while ago (see here) but the answer does not work for equations.

How to do that?

2

3 Answers 3

34

Here are some additions using tcolorbox. You can use a macro \tcbhighmath which is designed for such a task. The style can be varied also by options given to this macro.

\documentclass{article}
\usepackage[skins,theorems]{tcolorbox}
\tcbset{highlight math style={enhanced,
  colframe=red,colback=white,arc=0pt,boxrule=1pt}}
\begin{document}
\begin{equation}
\tcbhighmath[drop fuzzy shadow]{\Delta = b^2 - 4ac}
\end{equation}

\begin{equation}
\tcbhighmath[boxrule=2pt,drop fuzzy shadow=blue]{E = m\cdot c^2}
\end{equation}

\begin{equation}
\tcbhighmath[boxrule=0.4pt,colframe=blue,drop fuzzy shadow=red]{a^2 + b^2} =
\tcbhighmath[arc=4pt,drop fuzzy shadow=green]{c^2}
\end{equation}

\begin{equation}
\tcbhighmath[boxrule=2pt,arc=1pt,colback=blue!10!white,colframe=blue,
  drop fuzzy shadow=red]{ \ln|x| = \int\limits_1^x t~dt }
\end{equation}

\begin{equation}
\tcbhighmath[fuzzy halo=1mm with blue!50!white,arc=2pt,
  boxrule=0pt,frame hidden]{ \ln|x| = \int\limits_1^x t~dt }
\end{equation}

\tcbset{myinner/.style={no shadow,shrink tight,extrude by=1mm,colframe=blue,
  boxrule=0.4pt,frame style={opacity=0.25},interior style={opacity=0.5}}}
\begin{equation}
\tcbhighmath[drop fuzzy shadow=red!50!yellow,colback=red!20!white]{
  \tcbhighmath[myinner]{\Delta} =
  \tcbhighmath[myinner]{b^2 - 4ac}}
\end{equation}

\end{document}

enter image description here

9

I can't say I know all the ins and outs of tcolorbox, but this demonstrates that it works with equation material.

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
Testing
\begin{equation}
\tcbox[nobeforeafter]{\( \Delta = b^2 - 4ac \)}
\end{equation}
\end{document}

enter image description here

4
  • For the intended purpose I would recommend the \tcbhighmath macro from tcolorbox instead of \tcbox. Nevertheless, you could achieve the same with \tcbox and additional options :-) Jul 7, 2013 at 15:59
  • @ThomasF.Sturm I defer to your expertise on tcolorbox. Thanks for the tip, which will aid me and the readers of this. Jul 7, 2013 at 16:02
  • @Steven B. Segletes: Is there any way to get rid of the rounded corners? I prefer sharp corners.
    – rainman
    Dec 24, 2017 at 5:21
  • @far.westerner Best to ask Thomas Sturm, who provided the other answer and who wrote the tcolorbox package. Dec 24, 2017 at 12:27
0

According to the Tcolorbox manual, they provide custom ams equation environments inside the tcolorbox so you don't even have to make an equation environment:

\begin{tcolorbox}[ams equation, colback=yellow, colframe=red]
\sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty
\end{tcolorbox}

They also provide environments like ams align (just replace with this option in the above), which is very handy.

1

You must log in to answer this question.

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