我想用 tcolorbox 模拟 beamer 的块环境,因为后者对我来说似乎更灵活。我有几个最终需要创建的框式环境。我的第一次(失败的)尝试是模拟块环境颜色。代码如下。
我的 consoleBox 环境很接近,但颜色不太正确(太暗)。我以为 beamer 皮肤可能会让我获得 beamer 颜色,但如果可以,我不确定它使用的是哪种颜色。
请提供指点!
大卫
\documentclass[aspectratio=169]{beamer}
\usepackage[skins]{tcolorbox}
\usecolortheme{rose}
\newenvironment{consoleBox}
{\usebeamercolor{block title}\usebeamercolor{block body}%
\begin{tcolorbox}[sharp corners,frame empty,coltitle=block title.fg,%
colbacktitle=block title.bg,colback=block body.bg,title=Console,%
boxrule=0.5pt,arc=4pt,left=0pt,right=6pt,top=6pt]}
{\end{tcolorbox}}
\begin{document}
\begin{frame}
\frametitle{Problem}
\begin{block}{Console}
This is the desired appearance.
\end{block}
\begin{consoleBox}
This is close but not quite right. The body background is way too
dark and the title background is a little too dark.
\end{consoleBox}
\begin{tcolorbox}[skin=beamer,title=Console]
This is an attempt with skins...one might think that the beamer
skin would use the beamer color theme?
\end{tcolorbox}
\end{frame}
\end{document}
答案1
Ignasi 在其评论中已经链接的答案的简化版本:
\documentclass[aspectratio=169]{beamer}
\usepackage[skins]{tcolorbox}
\usecolortheme{rose}
\newtcolorbox{consoleBox}[2][]{%
colbacktitle=structure.fg!20!white,
coltitle=structure.fg,
colback=block title.bg!40!white,
title=#2,
boxrule=0pt,
sharp corners,
#1
}
\begin{document}
\begin{frame}
\frametitle{Problem}
\begin{block}{Console}
This is the desired appearance.
\end{block}
\begin{consoleBox}{Console}
This is close but not quite right. The body background is way too
dark and the title background is a little too dark.
\end{consoleBox}
\end{frame}
\end{document}
使用新的 tcolorbox 内部主题可以进一步简化代码 (https://www.ctan.org/pkg/beamertheme-tcolorbox)。此主题将自动从您正在使用的主题中获取颜色、形状等:
\documentclass[aspectratio=169]{beamer}
\usepackage[skins]{tcolorbox}
\usecolortheme{rose}
\useinnertheme{tcolorbox}
\newtcolorbox{consoleBox}[2][]{%
title=#2,
#1
}
\begin{document}
\begin{frame}
\frametitle{Problem}
\begin{block}{Console}
This is the desired appearance.
\end{block}
\begin{consoleBox}{Console}
This is close but not quite right. The body background is way too
dark and the title background is a little too dark.
\end{consoleBox}
\end{frame}
\end{document}