![为什么我的 beamer 模板可以工作,但是如果我调用父模板 [blocks] 却不工作?](https://linux22.com/image/417941/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84%20beamer%20%E6%A8%A1%E6%9D%BF%E5%8F%AF%E4%BB%A5%E5%B7%A5%E4%BD%9C%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E6%88%91%E8%B0%83%E7%94%A8%E7%88%B6%E6%A8%A1%E6%9D%BF%20%5Bblocks%5D%20%E5%8D%B4%E4%B8%8D%E5%B7%A5%E4%BD%9C%EF%BC%9F.png)
我正在尝试为我的 beamer 主题创建两种不同风格的块,一种有轮廓,另一种是倒置的。我已经实现了它们,但这是关于正确的选择方法。所以这是我的 MWE:
\documentclass{beamer}
\usepackage{ifthen}
\defbeamertemplate*{block alerted begin}{mytest}[1][outline]{%
\ifthenelse{\equal{#1}{outline}}%
{%
Beginn Outline%
}%
{%
\ifthenelse{\equal{#1}{inverted}}
{%
Beginn Inverted%
}%
{%
}%
}%
}
\defbeamertemplate*{block alerted end}{mytest}[1][outline]{%
\ifthenelse{\equal{#1}{outline}}%
{%
Beginn Outline%
}%
{%
\ifthenelse{\equal{#1}{inverted}}
{%
Beginn Inverted%
}%
{%
}%
}%
}
\begin{document}
\begin{frame}[label=myframe]
\begin{alertblock}{}
Test
\end{alertblock}
\end{frame}
\setbeamertemplate{blocks}[mytest][inverted]
\againframe{myframe}
\setbeamertemplate{blocks}[mytest][outline]
\againframe{myframe}
\setbeamertemplate{block alerted begin}[mytest][inverted]
\setbeamertemplate{block alerted end}[mytest][inverted]
\againframe{myframe}
\end{document}
如您所见,我定义了阻止警报模板的两个选项,然后针对不同的框架调用它。然而,我得到的结果如下:
因此,在我尝试设置父模板后,我在第一张幻灯片上打印了[inverted]
或[outline]
,但并没有设置它。但是对每个单独模板的调用都有效。据我了解手册,它应该有效:
父级 Beamer 模板更改此父级模板会更改普通块、警报块和示例块的模板。
示例:\setbeamertemplate{blocks}[default]
示例:\setbeamertemplate{blocks}[rounded][shadow=true]
因此,似乎出于某种我不知道的原因,我可以通过模板本身调用模板,但不能通过父模板调用模板,我不明白为什么会出现这种情况。有人能解释一下吗?
答案1
您还必须定义mytest
样式的父模板:
\documentclass{beamer}
\usepackage{ifthen}
\defbeamertemplateparent{blocks}[mytest]{block alerted begin,block alerted end}[1][outline]{[#1]}
\defbeamertemplate{block alerted begin}{mytest}[1][outline]{%
\ifthenelse{\equal{#1}{outline}}%
{%
Beginn Outline%
}%
{%
\ifthenelse{\equal{#1}{inverted}}
{%
Beginn Inverted%
}%
{%
}%
}%
}
\defbeamertemplate{block alerted end}{mytest}[1][outline]{%
\ifthenelse{\equal{#1}{outline}}%
{%
Beginn Outline%
}%
{%
\ifthenelse{\equal{#1}{inverted}}
{%
Beginn Inverted%
}%
{%
}%
}%
}
\setbeamertemplate{blocks}[mytest][outline]
\begin{document}
\begin{frame}[label=myframe]
\begin{alertblock}{}
Test
\end{alertblock}
\end{frame}
\setbeamertemplate{blocks}[mytest][inverted]
\againframe{myframe}
\setbeamertemplate{blocks}[mytest][outline]
\againframe{myframe}
\setbeamertemplate{block alerted begin}[mytest][inverted]
\setbeamertemplate{block alerted end}[mytest][inverted]
\againframe{myframe}
\end{document}