4

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}

1 Answer 1

5
\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}
7
  • I added the hbox, because I want to restrict the size of the box to fit the width of whatever is inside the box. Dropping the hbox-option makes align* work, however it obtains space at the sides, as well as on top. How can i fit the width without the hbox-option?
    – Tim Hilt
    Commented Oct 30, 2018 at 8:52
  • an align is a display construct, it is always full width. if you want hbox you can use an inline construct such as $\begin{aligned} rather than align. You would get exatly the same issues with a simple \fbox, \fbox{\begin{align} does not work, \fbox{$\begin{aligned} does. @TimHilt Commented Oct 30, 2018 at 8:54
  • Can you maybe point me to some documentation that explains the $\begin{...} syntax? So far i haven't found anything on the internet, nor in the LaTeX Companion and i don't really understand how to use this! @DavidCarlisle
    – Tim Hilt
    Commented Oct 30, 2018 at 20:56
  • @TimHilt $ is just the basic way to enter inline math, like $1+x^2$ and aligned is described in the amsmath documentation amsldoc.pdf as an inline version of align for making a term in a math expression rather than an entire display. Commented Oct 30, 2018 at 21:02
  • @TimHilt I put both versions in the answer. Commented Oct 30, 2018 at 21:04

You must log in to answer this question.

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