Beamer:在框架标题中添加徽标(修改 Metropolis)

Beamer:在框架标题中添加徽标(修改 Metropolis)

我正在尝试修改都市主题以在右侧包含一个徽标。

但是,每当我这样做时,标题文本都会被推上去,我似乎无法解决这个问题。我希望右侧的徽标与文本大致齐平,然后黑线应该出现在文本下方。

\documentclass[18pt]{beamer}

\usetheme{metropolis}
\title{Minimal working example}  %Optional
\institute{Somewhere}  %Optional
\author{Me} %Optional
\date{Insert date, month, year here}


\defbeamertemplate*{frametitle}{withlogo}{%
  \nointerlineskip%
  \begin{beamercolorbox}[%
      wd=\paperwidth,%
      sep=0pt,%
      leftskip=2.2ex,%
      rightskip=2.2ex,%
      ht=5.1em 
    ]{frametitle}%
    % \metropolis@frametitlestrut@start%
    %\vspace{2em}
    % Using vbox as suggested to ensure that single or double line of text
    % is centred at same point (vertically aligned)
    % suggest at
    % https://tex.stackexchange.com/questions/56300/how-can-i-vertically-align-a-beamercolorbox
    %
    \vbox to3em{\vfill
      \raggedright
      \hspace{0.5em}\insertframetitle%
      \vfill}
    \nolinebreak%
    \par
    \vspace{-1.0em}
    \noindent\textcolor{black}{\rule{4.2em}{0.06em}}
    \vspace{0.1em}
    \includegraphics[height=2em]{img/logo}
    \end{beamercolorbox}%

}

\setbeamertemplate{frametitle}[withlogo]

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}[t]
  \frametitle{Slide I}
\end{frame}

\end{document}

答案1

使用表格环境可以轻松对齐内容而无需进行太多猜测。

在这种情况下,只需添加nicematrix包,您便可获得对长标题的列宽和多行单元格的自动调整支持。

b

A

\documentclass[18pt]{beamer}

\usetheme{metropolis}
\title{Minimal working example}  %Optional
\institute{Somewhere}  %Optional
\author{Me} %Optional
\date{Insert date, month, year here}

\usepackage{nicematrix} % added <<<<<<<<<<<<<<<<<<<<<<

\defbeamertemplate*{frametitle}{withlogo}{%
    \nointerlineskip%
    \begin{beamercolorbox}[%
        wd=\paperwidth,%
        sep=1.5em,%
        leftskip=2.2ex,%
        rightskip=2.2ex,%
        ht=5.1em 
        ]{frametitle}%
        \begin{NiceTabular}[width=\paperwidth]{X[5,l]X[l]}
            \Block{}{\insertframetitle} &   \Block{}{\includegraphics[height=2em]{example-grid-100x100pt}}
        \end{NiceTabular}
    \end{beamercolorbox}%
}

\setbeamertemplate{frametitle}[withlogo]

\begin{document}
    
    \begin{frame}
        \titlepage
    \end{frame}
    
    \begin{frame}[t]
        \frametitle{Slide I short title}
    \end{frame}

    \begin{frame}[t]
    \frametitle{Slide I Insert date, month, year here a rather long text which fits on several lines}
\end{frame}
    
\end{document}

如果您想要(并看到)在分配给框架标题的空间下方有黑色规则,则需要更改默认颜色并使用此代码。

d

\setbeamercolor{titlecolors}{fg=blue,bg=green!10}   
\defbeamertemplate*{frametitle}{withlogo}{%
    \nointerlineskip%
    \begin{beamercolorbox}[%
        wd=\paperwidth,%
        sep=1.5em,%
        leftskip=2.2ex,%
        rightskip=2.2ex,%
        ht=5.1em 
        ]{titlecolors}%
        \begin{NiceTabular}[width=0.9\paperwidth]{@{}X[5,l]X[c]}[rules/color=black,rules/width=0.06em]
            \Block{}{\insertframetitle} &\Block{}{\includegraphics[height=2em]{example-grid-100x100pt}}\\ \cline{1}
        \end{NiceTabular}
    \end{beamercolorbox}%
}

使用默认颜色和白色规则

\begin{NiceTabular}[width=0.9\paperwidth]{@{}X[5,l]X[c]}[rules/color=white,rules/width=0.06em]

埃

答案2

这是一个有点硬编码的例子,但它有效,有一次我用这种方法,不知道它是对还是错,但我不会与你分享,也许它可以有所帮助(你可以将你的徽标放在你想要的任何地方使用\hspace{}和/或\vspace{}

    \documentclass[aspectratio=169]{beamer}
    \usetheme{Madrid}
    \usepackage[T2A]{fontenc}
    \usepackage[utf8]{inputenc}
    \usefonttheme{serif}
    \usepackage{array}
    \usepackage{colortbl}
    \usepackage{hhline}
    \usepackage[english]{babel}
    \usepackage{lmodern}
    
    
    \title{TITLE}
     \logo{
        \includegraphics[width=1.5cm]{example-image-a.png}
        \hspace{0.1cm}
         } 
    \author{AUTHOR}
    \institute[] % (optional)
    {
     \normalsize Faculty of Electronics\\
     group ...\\
    National Technical University of Ukraine "Igor Sikorsky Kyiv Polytechnic Institute" 
    }
    \begin{document}
    \begin{frame}
    \titlepage{}
    \end{frame}
    
    
    \begin{frame}
    Text
    \end{frame}
    
    \end{document}

在此处输入图片描述

相关内容