I have placed an image on the top-right corner of each frame in my beamer presentation. I have tried to get it right there in the perfect size, where its height is the same as the title rectangle. However, it is only the case when each frame only has a title and not a subtitle. When I add the subtitle and the rectangle of the subtitle is added, the logo is not vertically aligned anymore. I would like it to ideally have the same height as the height of the title and subtitle combined, or at least get vertically aligned in frames where I add a subtitle.
I use the following code for placing my logo on each frame top-right corner.
\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}}
MWE:
\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}

\addtobeamertemplate, add two new commands, one aligned when you don't have a subtitle and one when you do that you could call inside\frametitle. But that's not that elegant. – Dušan Stokić Feb 23 '22 at 15:56