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}
  • Why don't you just change theme to something which does it this way? – cfr Apr 14 '14 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. – maja zaloznik Apr 14 '14 at 14:36

1 Answers1

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

Gonzalo Medina
  • 505,128