基于 Tikz 的 beamer 框架

基于 Tikz 的 beamer 框架

我根据以下讨论创建了一个 beamer 环境:投影仪幻灯片中是否有一个简单的命令可以设置可用高度?唯一的问题是它不适用于覆盖。这是 MWE(要查看错误,请取消注释以 开头的行\only):

\documentclass{beamer}
\usepackage{tikz,environ}

\makeatletter
\NewEnviron{tikzframe}[2][c]{%
\begin{frame}[#1]{#2}
    \global\beamer@shrinktrue
    \gdef\beamer@shrinkframebox{\setbox\beamer@framebox=\vbox to\beamer@frametextheight{
    \begin{tikzpicture}[x=.5\linewidth,y=0.5\beamer@frametextheight]
        \path[use as bounding box] (-1,-1) rectangle (1,1);
        \BODY
    \end{tikzpicture}}}
\end{frame}}

%\NewEnviron{tikzframe}[2][c]{%
%\begin{frame}[#1]{#2}%
%   \begin{tikzpicture}[x=.5\linewidth,y=0.4\paperheight]
%      \path[use as bounding box] (-1,-1) rectangle (1,1);
%      \BODY
%   \end{tikzpicture}
%\end{frame}}

\begin{document}

\begin{tikzframe}{Title}
    \node at (-.5,0) {A};
    \node at (.5,0) {B};
%   \only<2>{\node at (.5,0) {B};}
\end{tikzframe}

\end{document}

你知道哪里出了问题吗?

答案1

这显示了如何计算框架文本高度。我使用 代替\ruletikzpicture 来简化问题。请注意,它没有为底部的导航按钮留出空间。

\documentclass{beamer}
\usepackage{tikz,environ}
\newlength{\mytextheight}
\makeatletter
\NewEnviron{tikzframe}[2][c]{%
\begin{frame}[#1]{#2}
    \setbox0=\vbox{%
      \vbox{}%
      {\parskip0pt\usebeamertemplate***{frametitle}\vskip0.25em}%
    }%
    \setlength{\mytextheight}{\dimexpr\textheight-\ht0-\dp0}%
    \rule{\linewidth}{\mytextheight}
\end{frame}}
\makeatother

\begin{document}

\begin{tikzframe}{Title}
%    \node at (-.5,0) {A};
%    \node at (.5,0) {B};
%   \only<2>{\node at (.5,0) {B};}
\end{tikzframe}

\end{document}

以下是 beamer 执行的计算:

  \ifx\beamer@frametitle\@empty%
    \setbox\beamer@frametitlebox=\box\voidb@x%
  \else%
    \setbox\beamer@frametitlebox=\vbox{%
      \vbox{}%
      {\parskip0pt\usebeamertemplate***{frametitle}\vskip0.25em}%
    }%
  \fi%
  \ifbeamer@plainframe%
    \beamer@frametextheight=\paperheight%
  \else%
    \beamer@frametextheight=\textheight%
  \fi%
  \advance\beamer@frametextheight by-\ht\beamer@frametitlebox%
  \advance\beamer@frametextheight by-\dp\beamer@frametitlebox%
  \advance\beamer@frametextheight by-\beamer@frametopskip%

相关内容