我有疑问投影机正如标题所暗示的那样奇怪。
我定义了两个标题模板:
\defbeamertemplate*{headline}{nosections}{%
}
\defbeamertemplate*{headline}{sections}{%
\setbeamercolor*{headline}{bg=white,fg=tuddunkelgrau}%
\hskip52mm%
\insertsectionnavigationhorizontal{0.5\paperwidth}{\hskip-8pt}{\hskip-8pt}
}
我也使用投影网格
\setbeamertemplate{background}[grid][step=10mm]
使用 tikz 放置一些路径或箭头。
在带有导航栏的幻灯片上,网格适合 tikz 坐标,但在没有导航栏的幻灯片上,网格具有导航栏高度的偏移。如果反过来,我可以理解,但那样对我来说没有任何意义。出了什么问题?
完整 MWE
\documentclass{beamer}
\usepackage{tikz}
\defbeamertemplate*{headline}{nosections}{%
}
\defbeamertemplate*{headline}{sections}{%
\setbeamercolor*{headline}{bg=white,fg=tuddunkelgrau}%
\hskip52mm%
\insertsectionnavigationhorizontal{0.5\paperwidth}{\hskip-8pt}{\hskip-8pt}
}
\setbeamertemplate{background}[grid][step=10mm]
\begin{document}
\setbeamertemplate{headline}[nosections]
\begin{frame}
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)},yscale=1]
\draw[line width = 1pt] (5,5) -- (7,7);
\end{tikzpicture}
\end{frame}
\end{document}
我可以通过为应该没有栏的模板定义一个宽度为零的导航栏来解决这个问题:
\defbeamertemplate*{headline}{nosections}{%
\setbeamercolor*{headline}{bg=white,fg=tuddunkelgrau}%
\hskip52mm%
\insertsectionnavigationhorizontal{0.5\paperwidth}{\hskip-8pt}{\hskip-8pt}
}
但我觉得这很愚蠢,什么是正确的方法?
PS:从性能角度来看,没有其他网格绘制方法可供选择。
答案1
一个简单的解决方法是使空标题的高度与正常标题的高度相同:
\defbeamertemplate*{headline}{nosections}{\vskip\headheight}
潜在的问题似乎是\pgfpointorigin
发生了偏移。它在网格定义中的使用如下:
\defbeamertemplate{background}{grid}[1][]
{%
\setkeys{beamer@backgroundgrid}{step=0.5cm,color=fg!10!bg}%
\setkeys{beamer@backgroundgrid}{#1}%
\begin{pgfpicture}{0cm}{0cm}{\the\paperwidth}{\the\paperheight}
\beamer@bggc
\pgfpathgrid[stepx=\beamer@bggw,stepy=\beamer@bggw]{\pgfpointorigin}{\pgfpoint{\the\paperwidth}{\the\paperheight}}
\pgfusepath{stroke}
\end{pgfpicture}%
}
如果将其pgfpicture
替换为\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)},yscale=1]
,则网格将根据页面定位。
\documentclass{beamer}
\usepackage{tikz}
\defbeamertemplate*{headline}{nosections}{\vskip0pt}
\defbeamertemplate*{headline}{sections}{%
\setbeamercolor*{headline}{bg=white,fg=tuddunkelgrau}%
\hskip52mm%
\insertsectionnavigationhorizontal{0.5\paperwidth}{\hskip-8pt}{\hskip-8pt}%
}
\makeatletter
\defbeamertemplate{background}{mygrid}[1][]
{%
\setkeys{beamer@backgroundgrid}{step=0.5cm,color=fg!10!bg}%
\setkeys{beamer@backgroundgrid}{#1}%
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)},yscale=1]
\beamer@bggc
\pgfpathgrid[stepx=\beamer@bggw,stepy=\beamer@bggw]{\pgfpointorigin}{\pgfpoint{\the\paperwidth}{\the\paperheight}}
\pgfusepath{stroke}
\end{tikzpicture}%
}
\makeatother
\setbeamertemplate{background}[mygrid][step=10mm]
\begin{document}
\setbeamertemplate{headline}[sections]
\begin{frame}
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)},yscale=1]
\draw[line width = 1pt] (5,5) -- (7,7);
\end{tikzpicture}
\end{frame}
\setbeamertemplate{headline}[nosections]
\begin{frame}
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)},yscale=1]
\draw[line width = 1pt] (5,5) -- (7,7);
\end{tikzpicture}
\end{frame}
\end{document}