Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  Loop Space 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
    
Related: Accessing other slides' titles in Beamer –  diabonas Sep 20 '13 at 19:43

4 Answers 4

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}
share|improve this answer

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.

share|improve this answer
4  
I think it should be pointed out that the \framebreak command only works when the allowframebreaks option has been given and this disables overlays. –  Loop Space 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 http://tex.stackexchange.com/a/519/86)

\documentclass{beamer}
%\url{http://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:

beamer with automatic use of previous frame title:

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.