“tcolobox” 中的“hbox”无法与 amsmath 中的左对齐方程配合使用

“tcolobox” 中的“hbox”无法与 amsmath 中的左对齐方程配合使用

我通读了手册并了解了 TeX.SE 上的一些问题,为了限制使用包生成的盒子的大小,tcolorbox我可以使用该hbox选项。

如果我使用此选项并fleqn传递到,amsmathhbox失败。请帮助我让这两个一起工作。

以下是 MWE:

\documentclass[12pt]{article}

\PassOptionsToPackage{fleqn}{amsmath} %if this is commented things work fine

\usepackage{mathtools} %loads amsmath
\usepackage{braket}
\usepackage{tcolorbox} 
\usepackage[a4paper, scale=0.9]{geometry}

\begin{document}

\begin{tcolorbox}[colback=gray!0!white,capture=hbox,arc=0mm]
\[
\begin{aligned}
    G(x_{1},x_{2}) &= \frac{\braket{ \overbrace{\ \ \Omega\ \ }^\text{vacuum} | \overbrace{T[ \hat{\phi}(\vec{x}_{1},t_{1})...\hat{\phi}(\vec{x}_{n},t_{n})]}^{\overbrace{\text{\footnotesize time-ordered product of operators}}^\text{\footnotesize earliest time to extreme right}} | \overbrace{\ \ \Omega\ \ }^\text{vacuum}}}{\braket{\Omega | \Omega}}
\end{aligned}
\]
\end{tcolorbox}

\end{document}

答案1

tcolorbox支持amsmath环境,您需要theorems库和empheq包才能访问它们。(我align*在这里使用是因为您使用aligned,但此时没有必要使用它,一个equation*就可以了。)

\documentclass[12pt]{article}

\PassOptionsToPackage{fleqn}{amsmath} %if this is commented things work fine

\usepackage{mathtools} %loads amsmath
\usepackage{braket}
\usepackage[theorems]{tcolorbox} 
\usepackage{empheq}
\usepackage[a4paper, scale=0.9]{geometry}

\begin{document}
\tcbset{highlight math style={colback=gray!0!white,capture=hbox,arc=0mm}}
\begin{empheq}[box=\tcbhighmath]{align*}
    G(x_{1},\dots,x_{n}) &= \frac{\braket{ \overbrace{\ \ \Omega\ \ }^\text{vacuum}
     | \overbrace{T[ \hat{\phi}(\vec{x}_{1},t_{1})\cdots\hat{\phi}(\vec{x}_{n},t_{n})]}^{\overbrace{\text{\footnotesize time-ordered product of operators}}^\text{\footnotesize earliest time to extreme right}} | \overbrace{\ \ \Omega\ \ }^\text{vacuum}}}{\braket{\Omega | \Omega}}
\end{empheq}

\end{document}

在此处输入图片描述

请注意,我个人不会使用这些\overbrace,并改变了 Greens 函数的参数。

\documentclass[12pt]{article}
\usepackage[a4paper, scale=0.9]{geometry}

\PassOptionsToPackage{fleqn}{amsmath} %

\usepackage{mathtools} %loads amsmath
\usepackage{braket}
\usepackage[theorems]{tcolorbox} 
\usepackage{empheq}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
\tcbset{highlight math style={colback=gray!0!white,capture=hbox,arc=0mm}}
\begin{empheq}[box=\tcbhighmath]{align*}
    G(x_{1},\dots,x_{n}) &= \frac{\braket{\tikzmarknode{O1}{\Omega}
     | \overbrace{T[ \hat{\phi}(\vec{x}_{1},t_{1})\cdots\hat{\phi}(\vec{x}_{n},t_{n})]}^{
     \text{\footnotesize\begin{tabular}{@{}c@{}}
      earliest time to extreme right\\
      time-ordered product of operators
\end{tabular}}} | 
     \tikzmarknode{O2}{\Omega}}}{\braket{\Omega | \Omega}}\quad
     \begin{tikzpicture}[overlay,remember picture]
     \draw[latex-] (O1) -- ++ (120:0.9) node[above,font=\footnotesize]{vacuum};
     \draw[latex-] (O2) -- ++ (60:0.9) node[above,font=\footnotesize]{vacuum};
    \end{tikzpicture}
\end{empheq}

\end{document}

在此处输入图片描述

相关内容