使 tikz 节点与 beamer 标题幻灯片中的幻灯片边缘齐平

使 tikz 节点与 beamer 标题幻灯片中的幻灯片边缘齐平

我正在使用环境制作标题幻灯片tikzpicture,标题幻灯片的顶部和左侧留有一些神秘的边距。我该如何正确修复这个问题(即,不是简单地摆弄和hspace[vpace除非通过“知情摆弄”])?我正在使用哥本哈根主题,它使用split外部主题。split外部主题定义了一个headline具有高度的元素2.5ex,但我不确定如何使用此信息或如何确定左边距的来源。

以下是示例:

文件:main.tex

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc}

\usetheme{Copenhagen}
\setbeamertemplate{navigation symbols}{}

\setbeamercolor{background canvas}{bg=yellow}

\defbeamertemplate*{title page}{customtitlepage}{%
\begin{tikzpicture}
    \fill[color=red, draw=none] (0,0.5\paperheight) rectangle(\paperwidth, \paperheight);

    \node[text width=\paperwidth, align=center, draw=green]
    at (0.5\paperwidth,1.0cm)
    {\color{black}\footnotesize\insertdate};

    \node[text width=\paperwidth, align=center, draw=green]
    at (0.5\paperwidth,2.0cm)
    {\color{black}\normalsize\insertinstitute};

    \node[text width=\paperwidth, align=center, draw=green]
    at (0.5\paperwidth,2.5cm)
    {\color{black}\Large\insertauthor};

    \node[anchor=north west, text width=0.5\paperwidth,align=right,draw=green] 
    at (0.5\paperwidth,0.5\paperheight) 
    {\color{black}\footnotesize\insertsubtitle};

    \node[anchor=south, text width=\paperwidth,align=left,draw=green]
    at (0.5\paperwidth,0.5\paperheight)
    {\color{yellow}\Large{\bf\inserttitle}};
\end{tikzpicture}
}

\makeatletter
\def\maketitle{%
\ifbeamer@inframe
\thispagestyle{empty}\titlepage
\else
\frame{\thispagestyle{empty}\titlepage}
\fi
}
\makeatother

\author{Joe Shmoe}
\title{The Battle of Turtle Gut Inlet}
\subtitle{The first privateer battle of the American Revolutionary War}
\institute{Continental Navy}
\date{July 4th, 1776}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\section{Normal Section}
\subsection{Normal Subsection}

\begin{frame}{Normal Frame}
    Normal things
\end{frame}

\end{document}

输出结果如下。红色矩形以及所有文本节点(字幕节点除外)的边界框应该与幻灯片的左边缘齐平,但实际上并非如此。此外,红色矩形应该与幻灯片的上边缘齐平,但实际上并非如此。

标题幻灯片:

封面

普通幻灯片(用于上下文):

普通幻灯片

答案1

避免 beamer 内置边距的最简单方法是使用[remember picture, overlay]选项并定位相对于 的所有内容(current page)。别忘了运行两次。

请注意,每个节点都包含文本周围的空间[inner sep](默认0.333em),因此您需要将其设置为零或[text width]减少.666em

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc}

\usetheme{Copenhagen}
\setbeamertemplate{navigation symbols}{}

\setbeamercolor{background canvas}{bg=yellow}

\defbeamertemplate*{title page}{customtitlepage}{%
\begin{tikzpicture}[remember picture,overlay]
    \fill[color=red, draw=none] (current page.west) rectangle(current page.north east);

    \node[text width={\paperwidth-.666em}, align=center, draw=green]
    at ($(current page.south)+(0pt,1cm)$)
    {\color{black}\footnotesize\insertdate};

    \node[text width={\paperwidth-.666em}, align=center, draw=green]
    at ($(current page.south)+(0pt,2cm)$)
    {\color{black}\normalsize\insertinstitute};

    \node[text width={\paperwidth-.666em}, align=center, draw=green]
    at ($(current page.south)+(0pt,2.5cm)$)
    {\color{black}\Large\insertauthor};

    \node[anchor=north west, text width={0.5\paperwidth-.667em},align=right,draw=green] 
    at (current page.center)
    {\color{black}\footnotesize\insertsubtitle};

    \node[anchor=south, text width={\paperwidth-.666em},draw=green]
    at (current page.center)
    {\color{yellow}\Large{\bf\inserttitle}};
\end{tikzpicture}
}

\makeatletter
\def\maketitle{%
\ifbeamer@inframe
\thispagestyle{empty}\titlepage
\else
\frame{\thispagestyle{empty}\titlepage}
\fi
}
\makeatother

\author{Joe Shmoe}
\title{The Battle of Turtle Gut Inlet}
\subtitle{The first privateer battle of the American Revolutionary War}
\institute{Continental Navy}
\date{July 4th, 1776}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\section{Normal Section}
\subsection{Normal Subsection}

\begin{frame}{Normal Frame}
    Normal things
\end{frame}

\end{document}

相关内容