我花了一点时间才确定这个问题的根本原因,但是使用 xelatex 和 tikzexternalize 生成的带有包含图像的自定义框架标题的 beamer 幻灯片不起作用。生成的幻灯片不包含任何框架内容。
该文件使用“xelatex --shell-escape *.tex”进行处理
我添加了一张它应该是什么样子的图像,因为有几条评论关于我为什么以这种方式在框架标题中使用图像。请注意,标题文本通常居中。
\documentclass[xcolor={dvipsnames},aspectratio=1610]{beamer}
\newdimen\leftlogosize
\newdimen\rightlogosize
\def\leftlogo{Physics_Logo.png}
\def\rightlogo{SanJac_Logo.png}
\leftlogosize=1.2cm
\rightlogosize=1.2cm
\newcommand{\drawlogo}[2]{%
\begingroup
\edef\x{\endgroup\noexpand\includegraphics[height=#2]{#1}}%
\x
}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west] at (current page.north west) {
\drawlogo{\leftlogo}{\leftlogosize}};
\node[anchor=north east] at (current page.north east) {
\drawlogo{\rightlogo}{\rightlogosize}};
\end{tikzpicture}}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepackage{tikz}
\tikzset{
external/system call={%
xelatex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode
-jobname "\image" "\texsource"}}
\tikzset{external/optimize=false}%
\tikzexternalize
\begin{document}
\begin{frame}
\frametitle{Title}
\begin{tikzpicture}
\draw (1,1) -- (2,2);
\end{tikzpicture}
\end{frame}
\end{document}
答案1
一个简单的解决方法是不使用 tikz 将简单的图像添加到框架的顶部,但这似乎有点过头了。
您向我们展示的图像可以轻松通过以下标题复制:
\documentclass[xcolor={dvipsnames},aspectratio=1610]{beamer}
\setbeamertemplate{headline}{%
\vskip0.5em%
\hspace*{0.5em}%
\includegraphics[height=1.2cm]{example-image-a}%
\hfill%
\includegraphics[height=1.2cm]{example-image-b}%
\hspace*{0.5em}%
}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepackage{tikz}
\tikzset{
external/system call={%
xelatex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode
-jobname "\image" "\texsource"}}
\tikzset{external/optimize=false}%
\tikzexternalize
\begin{document}
\begin{frame}
\begin{tikzpicture}
\draw (1,1) -- (2,2);
\end{tikzpicture}
\end{frame}
\end{document}
如果您还想显示框架标题,我建议使用以下框架标题定义:
\makeatletter
\setbeamertemplate{frametitle}{
\ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
\@tempdima=\textwidth%
\advance\@tempdima by\beamer@leftmargin%
\advance\@tempdima by -4.2cm%
\advance\@tempdima by\beamer@rightmargin%
\vskip-0.4cm%
\hspace*{0.5em}%
\hspace*{-\beamer@leftmargin}%
\raisebox{-0.5cm}{\includegraphics[height=1.2cm]{example-image-a}}%
\hspace*{0.5em}%
\begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima,ht=1.2cm,dp=0cm]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fteleft\endcsname\fi%
\strut\insertframetitle\strut\par%
{%
\ifx\insertframesubtitle\@empty%
\else%
{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
\fi
}%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
\hspace*{0.5em}%
\raisebox{-0.5cm}{\includegraphics[height=1.2cm]{example-image-b}}%
\hspace*{0.5em}%
}
\makeatother