我正在尝试使用该包对齐 Beamers Metropolis 主题标题中的某些图像tikz
。(也许还有更好的方法。)
现在,我使用yshift
和对齐它们xshift
。但是,使用这种手动方法无法完美对齐它们,因此在高分辨率演示中看起来很奇怪,您会看到偏移:
\usepackage{tikz}
% headline images
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.24pt, xshift = 4.2pt] at (current page.north east) {\includegraphics[height=1cm]{img/image2.png}};
\end{tikzpicture}}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.13pt, xshift = -64.8pt] at (current page.north east) {\includegraphics[height=1cm]{img/image1.png}};
\end{tikzpicture}}
根据大都市文件:
\newlength{\metropolis@frametitle@padding}
\setlength{\metropolis@frametitle@padding}{2.2ex}
\newcommand{\metropolis@frametitlestrut@start}{
\rule{0pt}{\metropolis@frametitle@padding +%
\totalheightof{% \ifcsdef{metropolis@frametitleformat}{\metropolis@frametitleformat X}{X}% }%
}% }
\newcommand{\metropolis@frametitlestrut@end}{
\rule[-\metropolis@frametitle@padding]{0pt}{\metropolis@frametitle@padding}
}
\defbeamertemplate{frametitle}{plain}{%
\nointerlineskip%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\end{beamercolorbox}%
}
对我来说可能的解决方案是:
- 将图像高度设置为框架标题的高度并进行手动水平对齐
- 将两个高度都设置为固定值(例如 1cm)
- 框架标题中图像放置的完全不同的方法
MWE(使用 XeLaTeX 编译):
\documentclass[unknownkeysallowed]{beamer}\usepackage[]{graphicx}\usepackage[]{color}
\usetheme[numbering = fraction]{metropolis}
\usepackage[american]{babel}
% frametitle images
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.24pt, xshift = 4.2pt] at (current page.north east) {\includegraphics[height=1cm]{example-image-b}};
\end{tikzpicture}}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.13pt, xshift = -44.8pt] at (current page.north east) {\includegraphics[height=1cm]{example-image-c}};
\end{tikzpicture}}
\begin{document}
% ##############################################################################
\section{Introduction}
% ------------------------------------------------------------------------------
\begin{frame}{Introduction}
test
\end{frame}
\end{document}
答案1
下面的解决方案有点丑陋,因为它首先测量不带徽标的 frametitle 的高度,然后将该高度用于徽标,所以基本上所有代码都存在两次......
\documentclass[unknownkeysallowed]{beamer}
%\usepackage{graphicx}
%\usepackage{color}
\usetheme[numbering = fraction]{metropolis}
\usepackage[american]{babel}
\makeatletter
\newsavebox{\mybox}
\setbeamertemplate{frametitle}{%
\nointerlineskip%
\savebox{\mybox}{%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\end{beamercolorbox}%
}
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\hfill%
\raisebox{-\metropolis@frametitle@padding}{\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image}}%
~%
\raisebox{-\metropolis@frametitle@padding}{\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image-a}}%
\hspace*{-\metropolis@frametitle@padding}
\end{beamercolorbox}%
}
\makeatother
\begin{document}
\begin{frame}
\frametitle{Introduction}
test
\end{frame}
\end{document}
如果有人想将此解决方案与框架标题下的进度条结合起来:
\documentclass[unknownkeysallowed]{beamer}
%\usepackage{graphicx}
%\usepackage{color}
\usetheme[numbering = fraction, progressbar=frametitle]{metropolis}
\usepackage[american]{babel}
\makeatletter
\newsavebox{\mybox}
\setbeamertemplate{frametitle}{%
\nointerlineskip%
\savebox{\mybox}{%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\end{beamercolorbox}%
}
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\hfill%
\raisebox{-\metropolis@frametitle@padding}{\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image}}%
~%
\raisebox{-\metropolis@frametitle@padding}{\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image-a}}%
\hspace*{-\metropolis@frametitle@padding}
\end{beamercolorbox}%
}
\addtobeamertemplate{frametitle}{}{%
\usebeamertemplate*{progress bar in head/foot}
}
\makeatother
\begin{document}
\begin{frame}
\frametitle{Introduction}
test
\end{frame}
\begin{frame}
\frametitle{Introduction}
test
\end{frame}
\end{document}
答案2
更新
终于!解决方案不需要复制粘贴frametitle
模板定义的当前定义,即对此定义更新具有鲁棒性!
\newsavebox{\mybox}
\makeatletter
\addtobeamertemplate{frametitle}{
\begin{lrbox}{\mybox}
\begin{minipage}{1.00\textwidth}
}{
\end{minipage}
\end{lrbox}
\nointerlineskip
\usebox{\mybox}
\tikzexternaldisable
\tikz[remember picture,overlay,every node/.style={inner sep=0,outer sep=0}]
\node[anchor=north east] at (current page.north east)
{
\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image}
~%
\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image-a}
}
;
\tikzexternalenable
}
\makeatletter
不幸的是,\appendix
仍然会取消这个的效果\addtobeamertemplate
,所以在命令之后重做\appendix
。
旧答案
接受答案中的解决方案破坏了框架标题中的进度条。进度条消失了。所以我重写了一点:
\makeatletter
\@ifundefined{mybox}{%
\newsavebox{\mybox}%
}{}%
\addtobeamertemplate{frametitle}{%
\savebox{\mybox}{%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start%
\insertframetitle%
\nolinebreak%
\metropolis@frametitlestrut@end%
\end{beamercolorbox}%
}%
}{%
\tikzexternaldisable%
\tikz[remember picture,overlay,every node/.style={inner sep=0,outer sep=0}]
\node[anchor=north east] at (current page.north east)
{
\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image}
~%
\includegraphics[height=\dimexpr\ht\mybox+\metropolis@frametitle@padding\relax]{example-image-a}
}
;
}
\makeatother
如果有人能以某种方式用扩展到模板当前定义的宏替换frametitle
里面的 beamer 模板的硬编码复制粘贴定义,那就太好了。\savebox