# Re-using the title of the previous Beamer slide

Is there a way to reference the title of the previous Beamer slide? Often, a sequence of slides have the same title, and I'd like to avoid having to repeat the title. I could define a macro for the title of each slide, but is there a way to grab the title of an arbitrary slide?

• Could you clarify something for me. Is your plan to have one long frame that you will manually or automatically break, or to have several frames (with explicit \begin{frame} ... \end{frame}) where you want to reuse the frame title? If you aren't sure: here's a test question. Will your slides use overlays? – Andrew Stacey Aug 8 '12 at 14:50
• They may or they may not use overlays. In my scenario I think I'd be manually breaking the frames, but it just so happens all the frames should have the same title. – jogloran Aug 8 '12 at 14:53
• Just out of interest, I'm also wondering why @PaulGaborit thinks this is a very unusual request. I would expect the exact opposite. – jogloran Aug 8 '12 at 14:57
• – diabonas Sep 20 '13 at 19:43

One possible solution is to let \frametitle do the work for you; in the following example, I modified \beamer@frametitle in such a way that each invocation of \frametitle globally defines a command that stores the title; the first time you use \frametitle, the command \Frametitlei is defined and containes the title; the second time \frametitle is used, the command \Frametitleii is created and stores the tile, and so on (the created command are all of the form \Frametitle<roman numeral>, where <roman numeral> is the roman numeral representation of the number of times \frametitle has been used); then you can use those commands to retrieve the names:

\documentclass{beamer}

\makeatletter
\newcounter{ftitle}
\long\def\beamer@@frametitle[#1]#2{%
\beamer@ifempty{#2}{}{%
\gdef\insertframetitle{{#2\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi}}%
\gdef\beamer@frametitle{#2}%
\stepcounter{ftitle}
\expandafter\gdef\csname Frametitle\romannumeral\theftitle\endcsname{#2}
\gdef\beamer@shortframetitle{#1}%
}%
}
\makeatother

\begin{document}

\begin{frame}
\frametitle{Test Frame Title One}
Test
\end{frame}

\begin{frame}
\frametitle{Test Frame Title Two}
Test
\end{frame}

\begin{frame}
\frametitle{\Frametitlei}
Test
\end{frame}

\begin{frame}
\frametitle{Test Frame Title Three}
Test
\end{frame}

\begin{frame}
\frametitle{\Frametitleii}
Test
\end{frame}

\end{document}


Beamer has a built-in facility for this: Inserting an explicit frame break using \framebreak instead of \end{frame} followed by \begin{frame} will put the content that follows onto the next frame, and the frame title is repeated automatically with a roman number appended. See this topic.

• I think it should be pointed out that the \framebreak command only works when the allowframebreaks option has been given and this disables overlays. – Andrew Stacey Aug 8 '12 at 14:52
• @Andrew. Disabling overlays is a severe restriction I wasn't aware of. Thanks for pointing this out. – AlexG Aug 8 '12 at 15:00

Your question is ever-so-slightly ambiguous. You open with:

Is there a way to reference the title of the previous Beamer slide?

and close with:

... is there a way to grab the title of an arbitrary slide?

These are different questions. The first simply wants to get the name of the previous(ly named) Beamer slide. The second wants full random access. Gonzalo has answered the second, here's a slightly cheaper way to get the first. It works on the same principle: we save the previous frame title (and subtitle) but it has a slightly different way of accessing it. The rule that I infer is that "If the frametitle isn't given, use the previous one.". The simplest way to achieve that is to insert the previous frame title (and subtitle) as the new ones at the start of the frame. Then any actual assignment will overrule it, but if no assignment is made then the defaults are there to be used.

Here's the code (with a little help from https://tex.stackexchange.com/a/519/86)

\documentclass{beamer}
%\url{https://tex.stackexchange.com/q/66274/86}

\makeatletter
\def\beamer@checkframetitle{%
\begingroup
\edef\temp{%
\endgroup
\noexpand\frametitle
[\unexpanded\expandafter{\beamer@savedshortframetitle}]%
{\unexpanded\expandafter{\beamer@savedframetitle}}%
}
\temp
\@ifnextchar\bgroup\beamer@inlineframetitle{}}

\long\def\beamer@@frametitle[#1]#2{%
\beamer@ifempty{#2}{}{%
\gdef\insertframetitle{{#2\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle
continuation}\fi}}%
\gdef\beamer@frametitle{#2}%
\gdef\beamer@shortframetitle{#1}%
\global\let\beamer@savedshortframetitle\beamer@shortframetitle
\global\let\beamer@savedframetitle\beamer@frametitle
}%
}
\global\let\beamer@savedshortframetitle\@empty
\global\let\beamer@savedframetitle\@empty

\makeatother

\begin{document}
\begin{frame}{The Frame Title}
A frame with a title
\end{frame}
\begin{frame}
A frame without a title
\end{frame}
\begin{frame}
\frametitle{The Next Frame Title}
A frame with a title
\end{frame}
\begin{frame}
A second frame without a title
\end{frame}
\end{document}


and the result:

:

• Thanks. This codes does pretty much what I want (reuse old frame title as long as I don't set a new one), but in its current form it seems broken, because it will also put the frametitle on top of all "section page"s. – rmh Sep 29 '16 at 9:45

This is a very unusual request. Maybe you can do without it.

Here is two solutions. The first two slides (with one frame) use \only. The last two slides (with two frames) use \section:

\documentclass{beamer}
\usepackage{lipsum}
\begin{document}
\begin{frame}
\frametitle{My first repeated title}

\only<1>{
\framesubtitle{first subtitle}
\begin{itemize}
\item first item
\item ...
\end{itemize}
}

\only<2>{
\framesubtitle{second subtitle}
\begin{enumerate}
\item \lipsum[2]
\item ...
\end{enumerate}
}
\end{frame}

\section{My long subject}

\begin{frame}
\frametitle{\insertsection}
\framesubtitle{first subtitle}
\begin{itemize}
\item first item
\item ...
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{\insertsection}
\framesubtitle{second subtitle}
\begin{enumerate}
\item \lipsum[2]
\item ...
\end{enumerate}
\end{frame}

\end{document}


I prefer this simple command because it can be easily adapted to your specific needs. And everything else is done as usual with \subsection{} and \subsubsection{}. As a nice side effect, every title and subtitle is a clickable reference.

\documentclass{beamer}
\newenvironment{slide}[0]{
\begin{frame}\ifx \insertsubsection \empty
\frametitle{\insertsection} \else
\frametitle{\insertsubsection}\framesubtitle{\insertsection} \fi
}{\end{frame}}

\begin{document}
\tableofcontents
\end{frame}

\section{my section}

\begin{slide}
first slide
\end{slide}

\subsection{my subsection}

\begin{slide}
second slide
\end{slide}
\end{document}
\end


And the result:

• Very nice solution!! – mrbela Dec 27 '18 at 16:16