总结:如何在框架标题的固定位置添加一个徽标,并用两行标题环绕它?
我正在创建一个自定义的 beamertheme。frametitle 必须在右上角包含一个徽标,并且需要能够处理跨越两行的框架标题。也许我忽略了一些显而易见的东西,但我似乎做不到正确。
我用过这篇博文由 Matthias Vogelgesang 创建的大部分自定义框架标题:
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\raisebox{-0.8mm}{\includegraphics[width=2cm,,height=0.4cm]{example-image}}
\vskip-0.8ex%
\end{beamercolorbox}
}
到目前为止,我已经设法使用以下方法将徽标包含在固定位置这个答案由 Gonzalo Medina 编写,从\raisebox{-0.8mm}{\includegraphics[width=2cm,,height=0.4cm]{example-image}}
frametitle 定义中删除,并将其添加到我的文档中:
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-0.05cm] at (current page.north east) {\includegraphics[width=2cm,height=0.4cm]{example-image}};
\end{tikzpicture}}
有没有办法让徽标保持原位,同时又能获得更长的标题以尊重徽标的边界?
MWE:(\usetheme{Test1}
对于第一个例子,\usetheme{Test2}
对于第二个例子)
\documentclass[10pt,dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{filecontents}
\begin{filecontents}{beamerthemeTest1.sty}
\setbeamerfont{frametitle}{size=\large}
\setbeamercolor{frametitle}{fg=JungleGreen,bg=Dandelion!60}
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\raisebox{-0.8mm}{\includegraphics[width=2cm,height=0.4cm]{example-image}}
\vskip-0.8ex%
\end{beamercolorbox}
}
\end{filecontents}
\begin{filecontents}{beamerthemeTest2.sty}
\setbeamerfont{frametitle}{size=\large}
\setbeamercolor{frametitle}{fg=JungleGreen,bg=Dandelion!60}
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\vskip-0.8ex%
\end{beamercolorbox}
}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-0.05cm] at (current page.north east) {\includegraphics[width=2cm,height=0.4cm]{example-image}};
\end{tikzpicture}}
\end{filecontents}
\usetheme{Test1}
%\usetheme{Test2}
\begin{document}
\begin{frame}{Test Frame}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\end{document}
答案1
是否添加rightskip=2cm
到您的选项列表beamercolorbox
中beamerThemeTest2.sty满足你的期望吗?
因此,MWE 的第 31 行如下所示:
\begin{beamercolorbox}[sep=0.3cm,rightskip=2cm,wd=\paperwidth]{frametitle}
这样,文本就不会出现在图像中。不过,我还没有检查垂直边距是否保持不变。
答案2
在第二个主题中,你可以将标题放在可以控制宽度的元素中,例如 a\parbox
或 aminipage
(这.8\textwidth
只是一个快速猜测,你可能需要稍微调整一下)
\documentclass[10pt,dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{filecontents}
\begin{filecontents*}{beamerthemeTest2.sty}
\setbeamerfont{frametitle}{size=\large}
\setbeamercolor{frametitle}{fg=JungleGreen,bg=Dandelion!60}
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\parbox{.8\textwidth}{\strut\insertframetitle\strut}%
\hfill
\vskip-0.8ex%
\end{beamercolorbox}
}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-0.05cm] at (current page.north east) {\includegraphics[width=2cm,height=0.4cm]{example-image}};
\end{tikzpicture}}
\end{filecontents*}
\usetheme{Test2}
\begin{document}
\begin{frame}{Test Frame}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\end{document}