[Tex/LaTex] Equations in tcolorbox. Vertical alignment

beamerequationstcolorboxvertical alignment

I am simply trying to put a frame around equations in my beamer slides.

For this purpose, I use the package tcolorbox.

The MWE below produces boxes where equations are almost aligned at the base of the box. I would want them to be centered vertically.

However, using "valign=center" has no effect.

(I already have a solution for the horizontal problem in the second equation and just didn't include it for MWE reasons)

\documentclass{beamer}
\usepackage{tcolorbox}
\newtcolorbox{equationframe}{
 valign=center,
}
\begin{document}
\begin{frame}
\begin{itemize}
\item[]
\begin{equationframe}
\begin{equation*}
p(x,y)=\begin{cases}
\min\{q(x,y),\frac{\pi({y})q(y,{x})}{\pi(x)}\}, \quad x\neq y\\
1-\int_{x\neq y} p(x,y)
\end{cases}
\end{equation*}
\end{equationframe}
\begin{equationframe}
\begin{equation*}
\pi(x)p(x,y)=\min\{\pi(x)q(x,y),\pi(y)q(y,x)\}=\pi(y)p(y,x)%
\end{equation*}
\end{equationframe}
\end{itemize}
\end{frame}
\end{document}

EDIT:

If I use the preamble

\documentclass{beamer}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\newtcolorbox{equationframe}{
 ams nodisplayskip
}

then I get

Missing $ inserted. \end{frame}

This is not problematic, since I realized using ams align* instead of ams nodisplayskip does the vertical alignment as I want, and my initial MWE compiles well. There is only one problem I with something I didn't include in the MWE:
To fit horizontally overlong equations, I used the macro

\newcommand\fiteq[1]{%
  \sbox{\mybox}{$\displaystyle#1$}%
  \ifdim\wd\mybox>.85\textwidth\resizebox{.85\textwidth}{!}{\usebox{\mybox}}%
  \else\usebox{\mybox}\fi%
}
\newsavebox{\mybox}

and then

\begin{equationframe}
\fiteq{A=......=B}
\end{equationframe}

Unfortunately, the align commands \\ and & do not work within this macro.

I just want a box that nicely contains equations. In normal latex a horizontally to long equation is not so problematic, but when there is a box around equations, and the equation runs through the boundary, it looks really stupid.

There are two options: (1) adjust the size of the box or (2) adjust the size of the equation.

The macro \fiteq{} does (2), and I really like the way it looks. It would be nice if someone could adapt the macro to work with align commands (it does work with the above solution, as long as no newlines or ampersands are used). If that is not possible, a solution that goes in the direction of (1) would be welcome too

Equations at bottom of the box

Best Answer

Load theorems library (I do it with class option most) and use ams or any other maths options.

ams set upper and lower parts to mathematical mode with \displaystyle. You don't need equation environments is these boxes. And you don't need valign.

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\newtcolorbox{equationframe}{
math
}
\begin{document}
\begin{frame}
\begin{itemize}
\item[]
\begin{equationframe}
p(x,y)=\begin{cases}
\min\{q(x,y),\frac{\pi({y})q(y,{x})}{\pi(x)}\}, \quad x\neq y\\
1-\int_{x\neq y} p(x,y)
\end{cases}
\end{equationframe}
\begin{equationframe}
\pi(x)p(x,y)=\min\{\pi(x)q(x,y),\pi(y)q(y,x)\}=\pi(y)p(y,x)%
\end{equationframe}
\end{itemize}
\end{frame}
\end{document}

enter image description here

Update: ams equation*, ams align*:

Instead of math, tcolorbox also offers some other mathematical boxes: ams equation, ams align, ams gather, ...

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

\begin{document}
\begin{frame}
\begin{tcolorbox}[ams equation*]
p(x,y)=\begin{cases}
\min\{q(x,y),\frac{\pi({y})q(y,{x})}{\pi(x)}\}, \quad x\neq y\\
1-\int_{x\neq y} p(x,y)
\end{cases}
\end{tcolorbox}

\begin{tcolorbox}[ams nodisplayskip, ams align*]
\pi(x)p(x,y) & =\min\{\pi(x)q(x,y),\pi(y)q(y,x)\}\\
& =\pi(y)p(y,x)%
\end{tcolorbox}
\end{frame}
\end{document}

enter image description here