[Tex/LaTex] Beamer: \framesubtitle without \frametitle

beamerframe-title

It it possible to use \framesubtitle without \frametitle in Beamer?
Because, I want to use \frametitle for sections and \framesubtitle for subsections.

Best Answer

Two approaches.

The first approach defines a magic word called please hide this title. Whenever the title is exactly this string, it will be hidden.

This definition of frametitle template is simply a copy of the original one in beamerouterthemedefault.sty line 149-169, except that the line generating the title is wrapped in a \ifx.

\documentclass{beamer}
\usetheme{Madrid}

\begin{document}

\makeatletter
\def\stringpleasehidethistitle{{please hide this title\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi}}
\defbeamertemplate*{frametitle}{only sub}[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%
    \ifx\insertframetitle\stringpleasehidethistitle%   check if magic word presents
    \else%                                             check if magic word presents
      \strut\insertframetitle\strut\par%               check if magic word presents
    \fi%                                               check if magic word presents
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
}

\frame{{please hide this title}{only subtitle}}
\frame{{I want title}{title appears!}}
\frame{{please hide this title}{only subtitle again!}}
\frame{{I want title the second time}{title appears again!}}

\end{document}


The second approach defines an alternative frametitle template which ironically shows no frametitle. This definition is simply a copy of the original one in beamerouterthemedefault.sty line 149-169, except that the line generating the title is commented out.

\documentclass{beamer}
\usetheme{Madrid}

\begin{document}

\makeatletter
\defbeamertemplate*{frametitle}{only sub}[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% <-- This line is commented out
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
}

\frame{{this title will be ignored}{only subtitle}}
\setbeamertemplate{frametitle}[default]
\frame{{switch back to the default}{title appears!}}
\setbeamertemplate{frametitle}[only sub]
\frame{{this title will be ignored again}{only subtitle again!}}
\setbeamertemplate{frametitle}[default]
\frame{{switch back to the default again}{title appears again!}}

\end{document}

The result is basically the same as before.

Related Question