align* 在 beamer tcolorbox 内

align* 在 beamer tcolorbox 内

虽然我已经放弃了beamer tcolorbox 内部对齐,我意识到我的mwe主题无法框住对齐方程式beamerthememwe.sty::

\mode<presentation>
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[most]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\usecolortheme[named=dcol]{structure}
\usepackage[]{biblatex}
\tcbuselibrary{theorems}

\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
  outerlayer/.style={%
    enhanced, sharpish corners=all, colbacktitle=dcol, coltitle=white, coltext=dcol, left=1mm,
    right=6mm, top=1mm, bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,
    % fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black}, % top
    % fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black}, % bottomSmall
    % fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGrey](segmentation.west) -- (segmentation.east);}
  },
  innerlayer/.style={outerlayer,
    noparskip, breakable, colback=dcol, coltitle=black, coltext=white, 
    fonttitle={\bfseries \scshape}, 
  bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}

\newtcolorbox{hlcard}[1][]{%
  innerlayer,hbox,
  #1
}

以及最小的 mwe:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage[]{biblatex}
% \usepackage{roboto}

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{card}
    \begin{hlcard}[ams align*]
        F&=ma\\
        E&=mc^{2}
    \end{hlcard}
  \end{card}
\end{frame}
\end{document}

给出错误:

! Missing } inserted.
<inserted text> 
                }
l.14 \end{frame}

? X
No pages of output.

如果我不使用我的主题并且简单地执行以下操作,则此错误就会消失:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage[]{biblatex}
% \usepackage{roboto}

\begin{document}
\begin{frame}\frametitle{Hello}
  % \begin{card}
    % \begin{hlcard}[ams align*]
  \begin{tcolorbox}[ams align*]
    F&=ma\\
    E&=mc^{2}
  \end{tcolorbox}
    % \end{hlcard}
  % \end{card}
\end{frame}
\end{document}

因此,我肯定遗漏了cardhlcard定义中的某些内容,但我周末无法找到它。

如您能给我一些启发,我将不胜感激。

更新我唯一的线索就是 是hbox罪魁祸首。我使用hboxhlcard使tcolorbox文本/公式仅换行,而不是完整的textwidth

注意:hlcard可以很好地覆盖单个内联方程。

答案1

您需要的是支持可用于任何数学模式aligned的环境amsmath,而不仅仅是显示。将选项tcolorbox的代码mathaligned以下设置相结合将为ams aligned您的框提供一个选项:

\tcbset{ams aligned upper/.style={before upper=$\displaystyle\aligned,
  after upper=\endaligned$},
ams aligned lower/.style={before lower=$\displaystyle\aligned,
  after lower=\endaligned$},
ams aligned/.style={ams aligned upper,ams aligned lower}}

示例输出

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}

\mode<presentation>
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[most]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\usecolortheme[named=dcol]{structure}
\usepackage[]{biblatex}
\tcbuselibrary{theorems}

\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
  outerlayer/.style={%
    enhanced, sharpish corners=all, colbacktitle=dcol, coltitle=white, coltext=dcol, left=1mm,
    right=6mm, top=1mm, bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,
    % fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black}, % top
    % fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black}, % bottomSmall
    % fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGrey](segmentation.west) -- (segmentation.east);}
  },
  innerlayer/.style={outerlayer,
    noparskip, breakable, colback=dcol, coltitle=black, coltext=white,
    fonttitle={\bfseries \scshape},
  bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}

\newtcolorbox{hlcard}[1][]{%
  innerlayer,hbox,
  #1
}

\tcbset{ams aligned upper/.style={before upper=$\displaystyle\aligned,
  after upper=\endaligned$},
ams aligned lower/.style={before lower=$\displaystyle\aligned,
  after lower=\endaligned$},
ams aligned/.style={ams aligned upper,ams aligned lower}}

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{card}
    \begin{hlcard}[ams aligned]
        F&=ma\\
        E&=mc^{2}
    \end{hlcard}
  \end{card}
\end{frame}
\end{document}

答案2

如果我没记错的话,无法将\hbox(或\tcbox) 与多行数学表达式一起使用。你可以做的是使用empheq带有\tcbox定义的环境。例如:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage{empheq}
\usepackage[]{biblatex}
% \usepackage{roboto}

\renewtcbox{hlcard}{%
    outerlayer,
   colback=dcol, 
   coltitle=black, 
   coltext=white, 
   fonttitle={\bfseries \scshape}, 
    bottomtitle=1mm,
    nobeforeafter,
    }

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{empheq}[box=\hlcard]{align*}
    F&=ma\\
    E&=mc^{2}
  \end{empheq}
\end{frame}

\end{document}

在此处输入图片描述

相关内容