5

I have following example code:

\usepackage{amssymb,amsmath,amsfonts} 
\usepackage{tcolorbox}
\usepackage{xcolor}
\begin{document}
    \begin{tcolorbox}[colback=lightgray,colframe=black]
    \vspace{-1\baselineskip}
    \begin{align}
    *
    \end{align}
    \end{tcolorbox}
\end{document}

I want to create a new environment so I don't have to copy and paste the whole thing over and over again. But everytime I create a new environment it doesn't work. Maybe you could help me.

1 Answers1

12

tcolorbox provides support for most of the align - like environments from amsmath, just use ams align or ams align* as option to a (new) tcolorbox environment.

\documentclass{article}
\usepackage[most]{tcolorbox}


\newtcolorbox{alignbox}[1][]{%
  colback=lightgray,colframe=black,
  before={},
  ams align,
  #1}

\begin{document}
\begin{alignbox}
  E &= mc^{2}
\end{alignbox}

\begin{alignbox}[ams align*]
  E &= mc^{2}
\end{alignbox}


\end{document}

enter image description here

  • @AlexRecuenco: Never say which should be the accepted answer. It is another answer. I don't crave for acceptance here for this post. I am no tick - stealer. –  Dec 19 '17 at 17:48
  • 1
    alright, sorry. I will remove that. I am thinking more in terms of the user that in a year will randomly pass by here, and try the first thing he reads... He would rather have found your answer first (In my opinion) – Alex Recuenco Dec 19 '17 at 18:07
  • @campa: No need to delete –  Dec 20 '17 at 08:25