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?

Vincent
  • 5,257

3 Answers3

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

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.

Yan King Yin
  • 1,743
  • 1
  • 19
  • 26
  • 1
    the solution provided by https://tex.stackexchange.com/questions/206944/tcolorbox-equation-and-fleqn-not-vertically-centered is \begin{tcolorbox}[ams align] is nicer – lehalle Feb 22 '19 at 13:51