1

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}

BMB
  • 13
  • A solution could be to, instead of using \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
  • You could put a tikzmark at the beginning and end of the title/subtitle and compute the size and location. OTOH, not sure how beamer handles duplicate tikzmarks. – John Kormylo Feb 23 '22 at 16:00
  • @DušanStokić that's exactly what I am looking for and I do not know how to implement it. – BMB Feb 23 '22 at 17:36
  • @JohnKormylo tbh, I don't think it would be a good idea to incorporate the tikz commands in every single frame. – BMB Feb 23 '22 at 17:38
  • Somewhat related: https://tex.stackexchange.com/questions/397523/tikz-based-beamer-frame – John Kormylo Feb 24 '22 at 03:48

1 Answers1

1

A solution using two \newcommand would look something like this:

\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}}

You can choose more appropriate names for your use case and adjust other parameters so that the image fits better.

Now you can call this two new commands in each frame:

\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}

This is the result:

enter image description here

Below is the entire file:

\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}

  • this works perfectly if I want to add it in every single frame. I was looking for a global solution like an if-clause which says if(title ) {do this}, if(title && subtitle){}. If there will be no improving solution, I will accept yours. – BMB Feb 23 '22 at 19:03