如何(以及理解)编辑 beamertheme.sty 来创建有边框/框架的块?

如何(以及理解)编辑 beamertheme.sty 来创建有边框/框架的块?

我正在尝试编辑 beamerthemeMyTheme.sty 文件以使其exampleblock变为框架/有界。虽然我见过这样的例子

我似乎无法做的是编辑样式文件以使每个示例块成为具有特定框架颜色的框架块。目前,我一直在摸索样式文件布局和语法的概念,例如:

\defbeamertemplateparent{blocks}[framed]{block begin,block end}[1][{[#1]}

组件在这里做什么[framed]?它是一个参数还是一个标志,用于指定所使用的块环境的新用法?这是覆盖环境block还是当使用单词“ blocks”时?设置或引用的参数是什么[1][{[#1]}?上面第一个链接中的另一个语句:

\defbeamertemplate{block begin}{framed}[1][]

这是指将要创建的每个块还是将被标记/设置为“框架“?这个数字又是指什么呢?

此代码使用以下内容生成一个框架块\usepackage{tcolorbox}

\begin{frame}{test}
\begin{tcolorbox}[title=My title,
colback=red!5!white,
colframe=red!75!black,
fonttitle=\bfseries]
This is a tcolorbox
Further text.
\end{tcolorbox}
\end{frame}

总的来说,我想了解如何创建主题样式,以便将框架块添加到示例块中,同时了解语句的作用。我一直在努力读完《The TEXbook》这本书唐纳德·E·克努斯,但我似乎忽略了整体情况。

答案1

主题定义比块定义更复杂,但如果您只是想使用框架块而不是默认beamer块,则无需定义新主题,只需定义新块。

以下示例展示了如何定义新的 tcolorboxes 以用作示例和警报块,并尊重 beamer 为这些块定义的颜色。默认 beamer 和 tcolorboxes 之间存在几何差异,但可以通过在框定义中添加几何选项来解决。

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

\usetheme{Warsaw}

\newtcolorbox{myexampleblock}[2][]{%
colframe = block title example.bg,
coltitle = block title example.fg,
colback = block body example.bg,
title = #2,
#1
}

\newtcolorbox{myalertblock}[2][]{%
colframe = block title alerted.bg,
coltitle = block title alerted.fg,
colback = block body alerted.bg,
title = #2,
#1
}

\begin{document}

\begin{frame}
\begin{exampleblock}{Example}
this a beamer block example
\end{exampleblock}

\begin{myexampleblock}{Example}
this a framed block example
\end{myexampleblock}

\begin{alertblock}{Alert}
this a beamer alerted block
\end{alertblock}

\begin{myalertblock}{Alert}
this a framed alerted block 
\end{myalertblock}
\end{frame}

\end{document}

在此处输入图片描述

更新:

为了创建一个beamertheme包含这些定义的文件,我们将它们全部(和包?)提取到beamerthemeTest.sty文件中并将其保留在工作文件夹中。

% beamerthemeTest.sty
\RequirePackage[most]{tcolorbox}

\usetheme{Warsaw}

\newtcolorbox{myexampleblock}[2][]{%
colframe = block title example.bg,
coltitle = block title example.fg,
colback = block body example.bg,
title = #2,
#1
}

\newtcolorbox{myalertblock}[2][]{%
colframe = block title alerted.bg,
coltitle = block title alerted.fg,
colback = block body alerted.bg,
title = #2,
#1
}

现在主文件如下所示:

\documentclass{beamer}

\usetheme{Test}

\begin{document}

\begin{frame}
\begin{exampleblock}{Example}
this a beamer block example
\end{exampleblock}

\begin{myexampleblock}{Example}
this a framed block example
\end{myexampleblock}

\begin{alertblock}{Alert}
this a beamer alerted block
\end{alertblock}

\begin{myalertblock}{Alert}
this a framed alerted block 
\end{myalertblock}
\end{frame}

\end{document}

答案2

您不需要创建新主题来获得块周围的边框。

相反,您可以使用新的 tcolorbox 内部主题(https://www.ctan.org/pkg/beamertheme-tcolorbox)并从那里进行调整:

\documentclass{beamer}

\usetheme{Warsaw}
\useinnertheme{tcolorbox}

\makeatletter
\tcbset{
 boxrule=1pt,
 frame style={draw,beamer@tcb@titlebg}
}
\makeatother

\begin{document}

\begin{frame}
\begin{block}{Block}
this a beamer block
\end{block}

\begin{exampleblock}{Example}
this a framed block example
\end{exampleblock}

\begin{alertblock}{Alert}
this a beamer alerted block
\end{alertblock}

\end{frame}

\end{document}

在此处输入图片描述

答案3

我不确定我是否理解了整个问题。就此而言,我可能会提供帮助setbeamertemplateparent

来自 beamer 的手册:

    \defbeamertemplateparent{⟨parent template name⟩}[⟨predefined option name⟩]{⟨child template list⟩}[⟨argument number⟩][⟨default optional argument⟩]{⟨arguments for children⟩}
该命令的效果是,每当有人调用 \setbeamertemplate{⟨父模板名称⟩}{⟨args⟩} 时,都会为 ⟨子模板列表⟩ 中的每个 ⟨子模板名称⟩ 调用命令 \setbeamertemplate{⟨子模板名称⟩}{⟨args⟩}。

因此,在

\defbeamertemplateparent{blocks}[framed]{block begin,block end}[1][{[#1]}

“framed” 是预定义选项名称,而 [1] 表示只有一个参数。我不喜欢深入理解整个语句,因为我可能会出错。不过,我知道您的defbeamertemplate示例仅适用于标记为 framed 的块。

我还认为,对于这个特殊的问题,beamer 手册比 Knuth 的书更有帮助。

相关内容