6

I'd like the frame title background - the bar at the top - to be a constant height, regardless of whether I have a title only or a subtitle as well.

One reason is consistency - I don't like the jumps from slide to slide. Another is that I'm also placing a logo in the top-right corner, and I don't know how else to keep its position constant relative to the top right corner..

Right now I'm kludging it by adding an invisible subtitle the same colour as the background, but I would appreciate a more elegant solution!

\PassOptionsToPackage{demo}{graphicx}
\documentclass{beamer}

\usepackage[english]{babel}
\usetheme{Madrid}
\definecolor{myblue}{RGB}{44,80,109}
\setbeamercolor{frametitle}{fg=white, bg=myblue}

\usepackage{textpos}
\addtobeamertemplate{frametitle}{}{%
\begin{textblock*}{10mm}(.94\textwidth,-1.3cm)
\includegraphics[height=1cm,width=1cm]{logo}
\end{textblock*}}

\begin{document}

\begin{frame}{Title}{Subtitle}
\end{frame}


\begin{frame}{Title with no Subtitle}
\end{frame}

\begin{frame}{Title with no Subtitle}{\textcolor{myblue}{placeholder for subtitle}}
\end{frame}

\end{document}
2
  • Why don't you just change theme to something which does it this way?
    – cfr
    Apr 14, 2014 at 13:21
  • Yeah, I could do that, but like I said, I've already found a way to fix it practically, I want to know how to do it generally. Thanks though. Apr 14, 2014 at 14:36

1 Answer 1

6

You can redefine the frametitle template (Madrid uses the default template whose original definition can be found in beamerouterthemedefault.sty):

\documentclass{beamer}
\usepackage[english]{babel}
\usetheme{Madrid}
\definecolor{myblue}{RGB}{44,80,109}
\setbeamercolor{frametitle}{fg=white, bg=myblue}

\makeatletter
\defbeamertemplate*{frametitle}{mydefault}[1][left]
{
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \if@tempswa\else\csname beamer@fte#1\endcsname\fi%
    \strut\insertframetitle\strut\par%
    {%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
}
\makeatother
\begin{document}

\begin{frame}
\frametitle{Title}
\framesubtitle{Subtitle}
test
\end{frame}

\begin{frame}{Title with no Subtitle}
test
\end{frame}

\end{document}

enter image description here

4
  • 1
    Got it! Remove the check if the subtitle is empty: "\ifx\insertframesubtitle\@empty%". Thanks! Apr 14, 2014 at 14:34
  • @maja exactly :) Apr 14, 2014 at 14:37
  • Hm, just noticed this only works as long as neither title is more than one line long.. Which is probably good presentation practice anyway :) Apr 14, 2014 at 19:38
  • 1
    @maja yes; one could extend the box so as to allow for two line titles, but then this will take much of the space reserved for the actual contents of the frame. One line titles are a recommended practice, anyway, as you mentioned. Apr 14, 2014 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .