自定义框架标题,徽标位于固定位置且标题为多行

自定义框架标题,徽标位于固定位置且标题为多行

总结:如何在框架标题的固定位置添加一个徽标,并用两行标题环绕它?

我正在创建一个自定义的 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到您的选项列表beamercolorboxbeamerThemeTest2.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}

在此处输入图片描述

相关内容