Search code examples
latexbeamer

Beamer Headline setup


I'm currently working on an own beamer template (actually I'm trying to remodell an existing power point design so I can do my presentations using Latex).

The existing template has a titlebar which shows a logo on the right and a small colored bar below the bar. This titlebar is shown for the titlepage, as well as for the text slides. Within the textslides the titlebar also contains the current frames title and subtitle, each in i its own font size and color.

Using the beamer user guide and other templates, I figured that every frame has a headline, which is sometimes used to show the current section, and a frame title where usually the frametitle and subtitle are shown. The headline is shown topmost, followed by the frame title. The frame title however, is not shown on the titlepage.

A (I hope as minimal as possible) working example of my setup is:

\setbeamercolor*{frametitle}{fg=white,bg=blue}
\setbeamercolor*{framesubtitle}{fg=gray,bg=blue}

\defbeamertemplate*{headline}{formusic}
    \ifx\insertframetitle\@empty%
        \begin{beamercolorbox}[wd=\paperwidth, ht=1.5cm]{frametitle}
            \hfill
            \includegraphics[scale=0.15]{logo.png}
        \end{beamercolorbox}
    \else%
    \fi%

\defbeamertemplate*{frametitle}{formusic}
    \ifx\insertframetitle\@empty%
        \begin{beamercolorbox}[wd=\paperwidth, ht=1.5cm]{frametitle}
        \end{beamercolorbox}
    \else%
        \ifx\insertframesubtitle\@empty%
            \begin{beamercolorbox}[wd=\paperwidth, ht=1.5cm]{frametitle}
                \raisebox{0.55cm}{\insertframetitle}
                \hfill
                \includegraphics[scale=0.15]{logo.png}
            \end{beamercolorbox}
        \else%
            \hbox{
                \vbox{
                \begin{beamercolorbox}[wd=\paperwidth, ht=0.7cm]{frametitle}
                    \insertframetitle
                \end{beamercolorbox}
                \begin{beamercolorbox}[wd=\paperwidth, ht=0.7cm]{framesubtitle}
                    \insertframesubtitle
                \end{beamercolorbox}}
                \includegraphics[scale=0.15]{logo.png}}
        \fi
    \fi%

The results of this can be seen in these slide headers. For the first, the titlepage this looks fine (I used the blue background color in order to visualize my problems), however for the other slides it does not look that good.

The headline does not seem to support the '\insertframe(sub)title' commands. Therefore I use a workaround where I display the empty titlebar within the headline for the first page with ifnum\c@framenumber=1, and for all other pages an empty headline. On these slides, the titlebar is displayed by the frametitle. This works - almost - as there is still a small white line visible between the frametitle and the top border of the slide.

My second problem is: How do I ideally arange the frametitle, -subtitle and logo in my titlebar? I played around a lot with beamercolorboxes, however I'm not 100% satisfied with what I have achieved so far. My attempt would be to have the frametitle and the subtitle in separate beamercolorboxes (this seems to be the most clean attempt, since I can use separately defined layouts for each, instead of switching font size and color), which are below each other. However now I don't know how to position the logo.


Edit: Added code example and images according to Werners suggestion and edited the text acordingly.


Solution

  • A quick workaround: not use a headline at all, but make sure that the frametitle will be shown on all frames, even those without frametitle:

    \documentclass{beamer}
    
    \setbeamertemplate{headline}{}
    
    \setbeamercolor{frametitle}{fg=white,bg=blue}
    \setbeamercolor{framesubtitle}{fg=gray,bg=blue}
    
    \makeatletter
    \patchcmd{\endbeamer@frameslide}{\ifx\beamer@frametitle\@empty}{\iffalse}{}{\errmessage{failed to patch}}
    \makeatother
    
    \makeatletter
    \setbeamertemplate{frametitle}{%
      \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
      \@tempdima=\textwidth%
      \advance\@tempdima by\beamer@leftmargin%
      \advance\@tempdima by\beamer@rightmargin%
      \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}
        \begin{minipage}{.81\paperwidth}
        \usebeamerfont{frametitle}%
        \vbox{}\vskip-1ex%
        \if@tempswa\else\csname beamer@fteleft\endcsname\fi%
        \strut\insertframetitle\par%
        {%
          \ifx\insertframesubtitle\@empty%
          \else%
          {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle\par}%
          \fi
        }%
        \end{minipage}%
        \quad\raisebox{-0.3cm}{\includegraphics[width=.1\paperwidth]{example-image-duck}}
        \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
      \end{beamercolorbox}%
    }
    \makeatother 
    
    \begin{document}
    
    \begin{frame}
        abc
    \end{frame} 
    
    \begin{frame}
    \frametitle{title}
        abc
    \end{frame} 
    
    \begin{frame}
    \frametitle{very long title which possible spans over multiples lines...}
        abc
    \end{frame} 
    
    \begin{frame}
    \frametitle{title}
    \framesubtitle{subtitle}
        abc
    \end{frame} 
    
    
    \begin{frame}
        abc
    \end{frame} 
    
    
    \end{document}