作为frame

作为frame

我正在使用这个问题的解决方案:在首页和幻灯片中定位徽标在标题框的右上角添加徽标。

我的问题有点复杂:

  • 我有一套 4 个徽标(pdf 和 png)
  • 有些幻灯片不应该有任何标志
  • 有些应该有一个标志
  • 有些应该有多个标志(在标题栏的右上方水平对齐)

我在用:

 \usetheme[height=9mm]{Rochester} 

而且我多次使用字幕。

我从链接的答案中复制并粘贴了 MWE:

\documentclass{beamer}
\usetheme[height=9mm]{Rochester} 
\usecolortheme{beaver}
\usepackage{tikz}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\begin{document}


\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {\includegraphics[height=0.8cm]{cat}};
\end{tikzpicture}}

\begin{frame}{Motivation}
Now the logo is visible
\end{frame}

\begin{frame}{Motivation}
\framesubtitle{A}
Now the logo is visible
\end{frame}

\end{document}

答案1

您可以定义frametitle模板,以便它通过从您在正确的点重新定义的宏中获取徽标来放置徽标。

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\def\thisframelogos{}

\newcommand{\framelogo}[1]{\def\thisframelogos{#1}}

\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {%
    \foreach \img in \thisframelogos {%
        \hspace{.5ex}%
        \includegraphics[height=0.8cm]{\img}%
    }%
};
\end{tikzpicture}}


\begin{document}

\begin{frame}{Motivation}
No logo
\end{frame}

\framelogo{cat}

\begin{frame}{Motivation}
Now the logo is visible
\end{frame}

\framelogo{cat,cat}

\begin{frame}{Motivation}
\framesubtitle{A}
Now we have two logos
\end{frame}

\end{document}

\thisframelogos宏存储了您想要放入下一帧标题中的图像列表。该\framelogo宏只是设置\thisframelogos

\thisframelogos发生更改时,更改后创建的每个框架都将使用其内容作为要放置的图像列表。使用\foreach中定义的命令放置图像tikz

要删除任何徽标,只需\framelogo{}在框架前使用即可。

作为frame

为了使技巧非“状态化”但适用于每帧,我们可以定义一个自定义键并借助重置\thisframelogosetoolbox参见

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz}
\usepackage{etoolbox}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\newcommand{\framelogo}[1]{\def\thisframelogos{#1}}

\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {%
    \foreach \img in \thisframelogos {%
        \hspace{.5ex}%
        \includegraphics[height=0.8cm]{\img}%
    }%
};
\end{tikzpicture}}

\BeforeBeginEnvironment{frame}{\framelogo{}}


\makeatletter
\define@key{beamerframe}{logos}[true]{\framelogo{#1}}
\makeatother


\begin{document}

\begin{frame}{Motivation}
No logo
\end{frame}

\begin{frame}[logos=cat]{Motivation}
Now the logo is visible
\end{frame}

\begin{frame}{Motivation}
No logo again
\end{frame}

\begin{frame}[logos={cat,cat}]{Motivation}
\framesubtitle{A}
Now we have two logos
\end{frame}

\end{document}

答案2

这与其他答案的想法类似,使用 提供的列表功能实现etoolbox

我定义了三个新的用户级命令来配置徽标。

\setmylogo{}

此命令将以逗号分隔的图像列表设置为当前徽标(如果在环境外使用,则将一直使用,直至另行通知frame)。例如,

\setmylogo{logo1,logo2}

要清除徽标,您可以使用空参数,即\setmylogo{}

第二条命令是

\addlogoleft{}

这会在现有徽标左侧添加以逗号分隔的图像列表。例如,如果徽标是logo1,logo2,则

\addlogoleft{logo0}

将设置徽标图像列表为logo0,logo1,logo2

相似地

\addlogoright{}

在现有徽标的右侧添加以逗号分隔的图像列表。

这是一个完整的例子:

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz,etoolbox}
\title{The title}
\institute[Inst.]{The Institute}
\date{\today}
\newcommand*\mylogo{%
  \renewcommand*\do[1]{\includegraphics[height=8mm]{##1}}%
  \dolistloop\mylogolist}
\newcommand*\setmylogo[1]{%
  \renewcommand*\mylogolist{}%
  \forcsvlist{\listadd\mylogolist}{#1}}
\newcommand*\addlogoleft[1]{%
  \global\let\oldmylogolist\mylogolist
  \renewcommand*\mylogolist{}%
  \forcsvlist{\listadd\mylogolist}{#1}%
  \forcsvlist{\listeadd\mylogolist}{\oldmylogolist}}
\newcommand*\addlogoright[1]{%
  \forcsvlist{\listadd\mylogolist}{#1}}
\newcommand*\mylogolist{}
\begin{document}
  \addtobeamertemplate{frametitle}{}{%
    \begin{tikzpicture}[remember picture,overlay]
      \node[anchor=north east,yshift=2pt] at (current page.north east) {\mylogo};
    \end{tikzpicture}}
  \begin{frame}{Motivation}
    No tiger.
  \end{frame}
  \setmylogo{tiger}
  \begin{frame}{Motivation}{A}
    Lone tiger.
  \end{frame}
  \addlogoleft{tiger,example-image-a}
  \begin{frame}{Mix}
    Lone tiger with document.
  \end{frame}
  \addlogoright{example-image-b,example-image-c}
  \begin{frame}{Mix}
    Lone tiger with documents.
  \end{frame}
  \setmylogo{tiger,tiger,tiger,tiger}
  \begin{frame}{Multiplication}
    Lots of tigers.
  \end{frame}
  \setmylogo{}
  \begin{frame}{None}
    No tiger.
  \end{frame}
\end{document}

老虎等等

编辑

由于您显然不想要如此灵活的功能,而更愿意为需要的每个框架指定徽标,因此这里有一个简化版本。在这种情况下,只需\setmylogo{}在相关环境中使用逗号分隔的图像列表即可frame

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz,etoolbox}
\title{The title}
\institute[Inst.]{The Institute}
\date{\today}
\newcommand*\mylogo{%
  \renewcommand*\do[1]{\includegraphics[height=8mm]{##1}}%
  \tikz[remember picture, overlay]\node[anchor=north east, yshift=2pt] at (current page.north east) {\dolistloop\mylogolist};}
\newcommand*\setmylogo[1]{%
  \renewcommand*\mylogolist{}%
  \forcsvlist{\listadd\mylogolist}{#1}%
  \mylogo}
\newcommand*\mylogolist{}
\begin{document}
  \begin{frame}{Motivation}
    No tiger.
  \end{frame}
  \begin{frame}{Motivation}{A}
  \setmylogo{tiger}
    Lone tiger.
  \end{frame}
  \begin{frame}{Mix}
  \setmylogo{tiger,example-image-a}
    Lone tiger with document.
  \end{frame}
  \begin{frame}{Mix}
  \setmylogo{example-image-b,example-image-c}
    Lone tiger with documents.
  \end{frame}
  \begin{frame}{Multiplication}
  \setmylogo{tiger,tiger,tiger,tiger}
    Lots of tigers.
  \end{frame}
  \begin{frame}{None}
    No tiger.
  \end{frame}
\end{document}

\setmylogo{}请注意,最后一帧不需要,因为标准默认值是没有徽标。

老虎数量减少

答案3

基于将参数传递给自定义框架选项您可以为 frametitle 定义自定义 beamer 模板并通过 frameoptions 选择它们

\documentclass{beamer}
\usetheme[height=9mm]{Rochester} 
\usecolortheme{beaver}
\usepackage{tikz}
\usepackage{etoolbox}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\makeatletter
\defbeamertemplate{frametitle}{mydefault}
{
    \vspace*{-1cm}%
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{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}%
}

\defbeamertemplate{frametitle}{imagetitle}[1]{%
    \vspace*{-1cm}%
    \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
    \@tempdima=\textwidth%
    \advance\@tempdima by\beamer@leftmargin%
    \advance\@tempdima by\beamer@rightmargin%
    \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{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}%
    \begin{tikzpicture}[remember picture,overlay]
        \node[anchor=north east,yshift=2pt] at (current page.north east) {\includegraphics[height=0.8cm]{#1}};
    \end{tikzpicture}   
}

\BeforeBeginEnvironment{frame}{%
    \setbeamertemplate{frametitle}[mydefault]%
}

\define@key{beamerframe}{imagetitle}[true]{%
    \setbeamertemplate{frametitle}[imagetitle]{#1}%
}
\makeatother

\begin{document}

    \begin{frame}
        \frametitle{bla}
        no logo
    \end{frame} 

    \begin{frame}[imagetitle=example-grid-100x100bp.pdf]
        \frametitle{bla}
        logo
    \end{frame}

    \begin{frame}[imagetitle=example-image.pdf]
        \frametitle{bla}
        \framesubtitle{blub}
        another logo
    \end{frame} 

    \begin{frame}
        \frametitle{bla}
        \framesubtitle{blub}
        no logo
    \end{frame}

\end{document}

相关内容