[Tex/LaTex] Math: align* inside Tcolorbox

alignmath-modetcolorbox

I'm framing certain elements in my document with the framed and the empheq– packages.

However, since i wanted a uniform way to just use one environment, i figured using tcolorbox would be the easiest way to go. I defined my own box as

\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced, colback=white, sharp corners, colframe=red, fonttitle=\bfseries, title=#1, center title}

However now, i can't include displayed math in a lot of environments inside that new box! In my case, i usually get away with just using the align* environment, but i didn't find anything on the internet, nor in the TcolorBox-Manual, that taught me how to add support for align* (which i think i have to).

Can someone help me out?

MWE:

\documentclass{article}

\usepackage{tcolorbox, mathtools}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced, colback=white, sharp corners, colframe=red, fonttitle=\bfseries, title=#1, center title}

\begin{document}

\begin{mybox}
  \begin{align*}
    z &= r \cos \varphi + \Im r \sin \varphi = r e^{\Im \varphi}\\
    r &= |z| = \sqrt{x^2 + y^2}
  \end{align*}
\end{mybox}

\end{document}

Error:

ERROR: Missing \endgroup inserted.

--- TeX said ---
<inserted text> 
\endgroup 
l.86 \end{mybox}

Best Answer

\documentclass{article}

\usepackage{tcolorbox, mathtools}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][]{before=\centering, drop fuzzy shadow, enhanced, colback=white, sharp corners, colframe=red, fonttitle=\bfseries, title=#1, center title}

\begin{document}

\begin{mybox}
  \begin{align*}
    z &= r \cos \varphi + \Im r \sin \varphi = r e^{\Im \varphi}\\
    r &= |z| = \sqrt{x^2 + y^2}
  \end{align*}
\end{mybox}

\end{document}

You need to remove the \hbox as align is a display construct.

enter image description here

Or, if you want the hbox, use an inline math markup, with aligned rather than align*

enter image description here

\documentclass{article}

\usepackage{tcolorbox, mathtools}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced, colback=white, sharp corners, colframe=red, fonttitle=\bfseries, title=#1, center title}

\begin{document}

\begin{mybox}
  $\begin{aligned}
    z &= r \cos \varphi + \Im r \sin \varphi = r e^{\Im \varphi}\\
    r &= |z| = \sqrt{x^2 + y^2}
  \end{aligned}$
\end{mybox}

\end{document}
Related Question