如何调整 tikz 创建的徽标的大小以适合每个框架中的标题矩形?

如何调整 tikz 创建的徽标的大小以适合每个框架中的标题矩形?

我在 Beamer 演示文稿的每个框架的右上角放置了一张图片。我试图让它以完美的尺寸出现在那儿,其高度与标题矩形相同。但是,只有当每个框架只有标题而没有副标题时才会出现这种情况。当我添加副标题并添加副标题的矩形时,徽标不再垂直对齐。我希望它的高度理想情况下与标题和副标题的总高度相同,或者至少在我添加副标题的框架中垂直对齐。

我使用以下代码将我的徽标放置在每个框架的右上角。

\addtobeamertemplate{frametitle}{}{%
        \begin{tikzpicture}[remember picture,overlay]
            \node[anchor=north east,xshift = 5pt, yshift=-23pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{MyLogo.pdf}};
    \end{tikzpicture}}

梅威瑟:

\documentclass[11pt]{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[export]{adjustbox}
    \usepackage{tikz}
    \usetikzlibrary{positioning}
    \setbeamertemplate{headline}{}
    \setbeamercovered{transparent}
    \usetheme{Madrid}
    \useoutertheme{miniframes} 
    \useinnertheme{circles}
    \setbeamercolor{subsection in head/foot}{bg=black,fg=white}
    
    \setbeamerfont{footline}{size=\fontsize{6}{6}\selectfont}
    \setbeamercolor{section in foot}{bg=gray,fg=white}
    \setbeamercolor{subsection in foot}{bg=black,fg=white}
    
    
    \setbeamertemplate{footline}
    {
        \hbox{%
            \begin{beamercolorbox}[wd=.30\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot}%
                \usebeamerfont{section in foot}\insertshortauthor
            \end{beamercolorbox}%
            % here I replace \insertsubtitle with \insertshorttitle
            \begin{beamercolorbox}[wd=.40\paperwidth,ht=2.6ex,dp=1ex,center]{subsection in foot}%
                \usebeamerfont{section in foot}\insertshorttitle
            \end{beamercolorbox}%
            \pgfsetfillopacity{0.5}
            \begin{beamercolorbox}[wd=.30\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot}%
                \usebeamerfont{section in foot}\insertshortauthor
            \end{beamercolorbox}%
        }%
        
        \vskip0pt%
    }
    
    \usepackage{xcolor}
    \usepackage{booktabs}
    \setbeamercolor{framesource}{fg=gray}
    \setbeamerfont{framesource}{size=\tiny}
    \newcommand{\source}[1]{\begin{textblock*}{4cm}(8.7cm,8.6cm)
            \begin{beamercolorbox}[ht=0.5cm,right]{framesource}
                \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
            \end{beamercolorbox}
    \end{textblock*}}
    \title[VeryCoolVeryCool]{\small\textbf{\documenttitle}}
    \subtitle{\small DVeryCoolVeryCoolVeryCool}
    \author[VeryCoolVeryCoolVeryCool] {VeryCoolVeryCool}
    \institute[]
    {} 
    \date[Winter 2021] % (optional)
    {VeryCoolVeryCoolVeryCoolVeryCoolVeryCool \vspace{0.1 in}}
    \newcommand{\documenttitle}{VeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCool}
    
    
    \addtobeamertemplate{frametitle}{}{%
        \begin{tikzpicture}[remember picture,overlay]
            \node[anchor=north east,xshift = 5pt, yshift=-23pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{Harvard.png}};
    \end{tikzpicture}}
    
    \begin{document}
        \begin{frame}[plain]
            \titlepage
        \end{frame}
        \section{Outline}
        \begin{frame}
            \frametitle[allowframebreaks]{Outline}
            \tableofcontents
        \end{frame}
        \section[intro]{A Cool Theory}
        \begin{frame}{Rules}
            \frametitle{Brief History }
            These are the principal rules:
        \end{frame}
        \begin{frame}
            \frametitle{Wow! Everyone is Smart HeRe}
            \framesubtitle{Except Me!}
        \end{frame}
\end{document}

答案1

使用两个的解决方案\newcommand看起来像这样:

\newcommand{\frameimage}{%
    \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north east,xshift = 5pt, yshift=-23pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{example-image-a}};
    \end{tikzpicture}}

\newcommand{\frameimagesub}{%
    \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north east,xshift = 5pt, yshift=-28pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{example-image-a}};
    \end{tikzpicture}}

您可以根据您的用例选择更合适的名称,并调整其他参数,以便图像更好地适应。

现在您可以在每个框架中调用这两个新命令:

\begin{document}
    \begin{frame}[plain]
        \titlepage
    \end{frame}
    \section{Outline}
    \begin{frame}
        \frametitle[allowframebreaks]{Outline \frameimage}
        \tableofcontents
    \end{frame}
    \section[intro]{A Cool Theory}
    \begin{frame}{Rules}
        \frametitle{Brief History \frameimage}
        These are the principal rules:
    \end{frame}
    \begin{frame}
        \frametitle{Wow! Everyone is Smart HeRe \frameimagesub}
        \framesubtitle{Except Me!}
    \end{frame}
\end{document}

结果如下:

在此处输入图片描述

以下是整个文件:

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[export]{adjustbox}
\usepackage{tikz}
\usetikzlibrary{positioning}
\setbeamertemplate{headline}{}
\setbeamercovered{transparent}
\usetheme{Madrid}
\useoutertheme{miniframes} 
\useinnertheme{circles}
\setbeamercolor{subsection in head/foot}{bg=black,fg=white}

\setbeamerfont{footline}{size=\fontsize{6}{6}\selectfont}
\setbeamercolor{section in foot}{bg=gray,fg=white}
\setbeamercolor{subsection in foot}{bg=black,fg=white}


\setbeamertemplate{footline}
{
    \hbox{%
        \begin{beamercolorbox}[wd=.30\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot}%
            \usebeamerfont{section in foot}\insertshortauthor
        \end{beamercolorbox}%
        % here I replace \insertsubtitle with \insertshorttitle
        \begin{beamercolorbox}[wd=.40\paperwidth,ht=2.6ex,dp=1ex,center]{subsection in foot}%
            \usebeamerfont{section in foot}\insertshorttitle
        \end{beamercolorbox}%
        \pgfsetfillopacity{0.5}
        \begin{beamercolorbox}[wd=.30\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot}%
            \usebeamerfont{section in foot}\insertshortauthor
        \end{beamercolorbox}%
    }%
    
    \vskip0pt%
}

\usepackage{xcolor}
\usepackage{booktabs}
\setbeamercolor{framesource}{fg=gray}
\setbeamerfont{framesource}{size=\tiny}
\newcommand{\source}[1]{\begin{textblock*}{4cm}(8.7cm,8.6cm)
        \begin{beamercolorbox}[ht=0.5cm,right]{framesource}
            \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
        \end{beamercolorbox}
\end{textblock*}}
\title[VeryCoolVeryCool]{\small\textbf{\documenttitle}}
\subtitle{\small DVeryCoolVeryCoolVeryCool}
\author[VeryCoolVeryCoolVeryCool] {VeryCoolVeryCool}
\institute[]
{} 
\date[Winter 2021] % (optional)
{VeryCoolVeryCoolVeryCoolVeryCoolVeryCool \vspace{0.1 in}}
\newcommand{\documenttitle}{VeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCoolVeryCool}


\newcommand{\frameimage}{%
    \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north east,xshift = 5pt, yshift=-23pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{example-image-a}};
    \end{tikzpicture}}

\newcommand{\frameimagesub}{%
    \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north east,xshift = 5pt, yshift=-28pt] at (current page.north east) {\includegraphics[width=2cm, height=0.92cm]{example-image-a}};
    \end{tikzpicture}}


\begin{document}
    \begin{frame}[plain]
        \titlepage
    \end{frame}
    \section{Outline}
    \begin{frame}
        \frametitle[allowframebreaks]{Outline \frameimage}
        \tableofcontents
    \end{frame}
    \section[intro]{A Cool Theory}
    \begin{frame}{Rules}
        \frametitle{Brief History \frameimage}
        These are the principal rules:
    \end{frame}
    \begin{frame}
        \frametitle{Wow! Everyone is Smart HeRe\frameimagesub}
        \framesubtitle{Except Me!}
    \end{frame}
\end{document}

相关内容