[Tex/LaTex] Logo on the top right of each slide in Warsaw theme

beamer

Related to this question, I am trying to put a logo on the top right side of each slide in a beamer document.

This is my code:

\documentclass[10pt]{beamer}
% This is the file main.tex
\usetheme{Warsaw}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\setbeamertemplate{navigation symbols}{}%remove navigation symbols
\setbeamercovered{transparent}
\makeatother
%\pgfdeclareimage[height=0.45cm]{logo}{figures/ubuntu-logo32}
%\logo{\pgfuseimage{logo}}
\title{title}
\author{Name Surname}
\institute{Institute\\[\medskipamount]\includegraphics[scale=0.2]{figures/ubuntu-logo32.png}}
%\email{alpha@beta.com}
\date{date\\ place}
\begin{document}

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

\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-6pt] at (current page.north east) {\includegraphics[scale=0.07]{figures/ubuntu-logo32.png}};
\end{tikzpicture}
}

\frame{
\transsplitverticalin
\frametitle{Summary}\tableofcontents
}

\section{Section}
\frame{\sectionpage}
\subsection{subsection}
\frame{
\frametitle{title}
\begin{block}{title}
title
\begin{itemize}
\item {title};
\item {title};
\item {title};
\item {title};
\end{itemize}
\end{block}

\begin{alertblock}{title}
title
\begin{itemize}
\item {title};
\end{itemize}
\end{alertblock}

\begin{exampleblock}{title}
title
\begin{itemize}
\item {title};
\item {title};
\item {title};
\item {title};
\end{itemize}
\end{exampleblock}
}
\end{document}

However, I noticed the following issues:

1) I have to manually select the position of the logo, which is a bit annoying. Is there any automatic way to position the logo?

2) It seems that my code "steal" some space before the first block. This is a particularly undesired effect, since it reduces the overall space for content. This is the difference between the slide with the logo:

enter image description here

and the slide without the logo:

enter image description here

How could I reduce the space above the first block without removing the logo on the top right of the slide?

Best Answer

Instead of using this tikz approach and dealing with the additional vertical space, you could add your logo to the definition of the frametitle

\documentclass[10pt]{beamer}

\usetheme{Warsaw}
\setbeamertemplate{navigation symbols}{}%remove navigation symbols

\makeatletter
\setbeamertemplate{frametitle}{%
    \nointerlineskip%
    \vskip-2pt%
    \hbox{\leavevmode
        \advance\beamer@leftmargin by -12bp%
        \advance\beamer@rightmargin by -12bp%
        \beamer@tempdim=\textwidth%
        \advance\beamer@tempdim by \beamer@leftmargin%
        \advance\beamer@tempdim by \beamer@rightmargin%
        \hskip-\Gm@lmargin\hbox{%
            \setbox\beamer@tempbox=\hbox{\begin{minipage}[b]{.92\paperwidth}%
                    \vbox{}\vskip-.75ex%
                    \leftskip0.3cm%
                    \rightskip0.3cm plus1fil\leavevmode
                    \insertframetitle%
                    \ifx\insertframesubtitle\@empty%
                    \strut\par%
                    \else
                    \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
                    \fi%
                    \nointerlineskip
                    \vbox{}%
                \end{minipage}%
                \hfill%
                \raisebox{.1cm}{\includegraphics[height=.5cm]{example-image}}%
                }%
                \beamer@tempdim=\ht\beamer@tempbox%
                \advance\beamer@tempdim by 2pt%
                \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
                    \usebeamercolor{frametitle right}
                    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
                    \pgfusepath{clip}
                    \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
                \end{pgfpicture}
                \hskip-\paperwidth%
                \box\beamer@tempbox%
            }%
            \hskip-\Gm@rmargin%
        }%
        \nointerlineskip
        \vskip-0.2pt
        \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
        \vskip-2pt
    }
\makeatother


\begin{document}

    \frame{
        \frametitle{title}
        \begin{block}{title}
            title
            \begin{itemize}
                \item {title};
                \item {title};
                \item {title};
                \item {title};
            \end{itemize}
        \end{block}

        \begin{alertblock}{title}
            title
            \begin{itemize}
                \item {title};
            \end{itemize}
        \end{alertblock}

        \begin{exampleblock}{title}
            title
            \begin{itemize}
                \item {title};
                \item {title};
                \item {title};
                \item {title};
            \end{itemize}
        \end{exampleblock}
    }
\end{document}

enter image description here