1

I'm trying to write a custom beamer theme. I got stuck on the frame title, trying to vertically center both Title and Title+Subtitle in a fixed-size beamercolorbox. Combining a couple of other people's solutions, I arrived at the combination of \ifx\insertframesubtitle\@empty and \vbox to 6ex{ \vfil. It looks exactly like I want now, but produces \hbox overfull for each frame. Another small-ish issue is that I had to manually put 6ex for the Title version and 6.05 for the Title+Subtitle version for them to be exactly the same size (no idea why). I would like a more elegant solution.

I would appreciate any help!

Main file:

\documentclass{beamer}

\usetheme{TEST}

\begin{document}

\begin{frame}{Frame}
\end{frame}

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

\end{document}

beamerthemeTEST.sty :

\mode<presentation>

\definecolor{salmon}{RGB}{240, 145, 145}
\setbeamercolor{frametitle}{fg=white, bg=salmon}
\setbeamerfont{frametitle}{size=\LARGE}
\setbeamerfont{framesubtitle}{size=\normalsize}

\defbeamertemplate*{frametitle}{}[1][]
{
    \nointerlineskip%
    \ifx\insertframesubtitle\@empty%
        \begin{beamercolorbox}[wd=\paperwidth, left, leftskip = 1ex]{frametitle}%
           \vbox to 6ex{%
            \vfil%
            \usebeamerfont{frametitle}\strut\insertframetitle%
            \vfil}%
        \end{beamercolorbox}%
    \else%
        \begin{beamercolorbox}[wd=\paperwidth, left, leftskip=1ex, rightskip=4ex]{frametitle}%
            \vbox to 6.05ex{%
            \vfil%
            \usebeamerfont{frametitle}\strut\insertframetitle\\%
            \usebeamerfont{framesubtitle}\strut\insertframesubtitle%
            \vfil}%
        \end{beamercolorbox}%
    \fi%
}
\mode<all>

EDIT: If I define the frame title inside the main file, the title on the Title-only frame moves up (is not centered).

EDIT2: I found the following solution for the hbox overfull (not clear on the mechanics, something to do with \vbox to):

\begin{beamercolorbox}[wd=\paperwidth, left]{frametitle}%
    \vbox to 40pt{\vfil%     
    \usebeamerfont{frametitle}\hspace{10pt}\strut\insertframetitle%
    \vfil}%
\end{beamercolorbox}%

Still trying to figure out a better way for different conditional values for \vbox to.

3
  • 1
    Can you please make a compilable example, including a class? Commented Apr 22 at 16:42
  • @samcarter_is_at_topanswers.xyz sorry, added the class. Now it's fully reproducible Commented Apr 22 at 19:15
  • @samcarter_is_at_topanswers.xyz I found an interesting thing when adding the class. In the Title slide, the title moves up (is not centered) if I define the template inside the main file rather than .sty. I split the MWE into two files. Commented Apr 22 at 19:35

1 Answer 1

1

You could take some inspiration from the default frametitle template on how to make a frametitle spanning the whole paperwidth without causing overfull boxes:

\documentclass[11pt]{beamer}

\makeatletter
\setbeamertemplate{frametitle}{%
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  % changed code from here
  \begin{beamercolorbox}[sep=0cm,left,wd=\the\@tempdima,leftskip=0.5cm,rightskip=0.5cm]{frametitle}
    \begin{minipage}[c][2cm][c]{\textwidth}
      \usebeamerfont{frametitle}%
      \strut\insertframetitle\strut\par
      \ifx\insertframesubtitle\@empty%
      \else
        {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle\strut\par}%
      \fi
    \end{minipage}
  \end{beamercolorbox}%
}
\makeatother

\setbeamerfont{frametitle}{size=\LARGE}
\setbeamerfont{framesubtitle}{size=\normalsize}

\definecolor{salmon}{RGB}{240, 145, 145}
\setbeamercolor{frametitle}{fg=white, bg=salmon}

\begin{document}

\begin{frame}
\frametitle{Frame}
test
\end{frame}

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

\begin{frame}
content...
\end{frame}

\end{document}

enter image description here enter image description here

2
  • Thanks. What I was trying to do is for the first slide to have "Frame" vertically centered. I'm also very confused with all these vocabulary, like \if@tempswa. Do you happen to know some source I could check to have step-by-step explanations of what you posted? Commented Apr 22 at 19:56
  • @ABraslavskiy See my updated answer. If you just want the title centred, a minipage might be a simple solution Commented Apr 22 at 20:18

You must log in to answer this question.

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