答案1
如需更多选项,请参阅https://www.ctan.org/pkg/tcolorbox
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\newtcolorbox{mybox}[2][]{%
colback=bg,
colframe=blue!75!black,
fonttitle=\bfseries,
coltitle=blue!75!black,
colbacktitle=bg,
enhanced,
attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
title=#2,
#1}
\begin{document}
\begin{frame}
\begin{mybox}{Hello there}
This is my own box with a mandatory title
and options.
\end{mybox}
\begin{mybox}[colframe=green!75!black,coltitle=green!75!black, ]{Hello there}
This is my own box with a mandatory title
and options.
\end{mybox}
\end{frame}
\end{document}
tcolorbox 内部主题的替代方案是,它将自动从 beamer 的警报和示例块中获取颜色:
\documentclass{beamer}
\useinnertheme[rounded]{tcolorbox}
\makeatletter
\tcbsetforeverylayer{
boxrule=3pt,
borderline={1pt}{0pt}{beamer@tcb@titlefg},
attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
}
\makeatother
\begin{document}
\begin{frame}
\begin{block}{Short title}
some text here
\end{block}
\begin{exampleblock}{A bit more long title}
some text here
\begin{alertblock}{ff}
dd
\end{alertblock}
\end{exampleblock}
\end{frame}
\end{document}