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.

I wonder how to suffix equivalent frametitles with a counter or index. So for example, when I would have two slides with the same \frametitle (e.g. "Marvelous title"), it should result in

Marvelous title (1)
Marvelous title (2)

I know, adding the "(1)" and "(2)" manually is not much work, but I'm asking myself whether it could be done automatically.

share|improve this question
1  
You can check the option frametitle continuation for slides that don't have overlays. –  percusse Aug 5 '12 at 20:40
    
@percusse Thanks, it seems that I also need the [allowframebreaks] flag for the relevant frames. However, although all frames also have a vertical top alignment [t], the continued frame aligns the text (also when it's exactly the same as on the previous slide) a little higher. Is this to be expected? –  Ailurus Aug 5 '12 at 22:51
    
Edit: This also happens when using [allowframebreaks=1]. Note, just for testing this option I'm using \pagebreak. The continued frame is the one that is off, it starts a little higher than other (normal) frames. –  Ailurus Aug 5 '12 at 22:59
    
It is indeed a little tricky and probably needs some modification. The main reason for that is usually the main slide is too full and hence needs to be divided into different parts and you can expect that the continuing frames need to be packed to minimize the extra frame number. So this suggestion might not be useful to you. –  percusse Aug 5 '12 at 23:02
    
According to the manual, using allowframebreaks is incompatible with overlays so this might not be what is wanted here. –  Loop Space Aug 10 '12 at 10:12

1 Answer 1

up vote 3 down vote accepted

Here's a solution for you. Each time the frame title is typeset, we write a line to the aux file. When read back in, this gives us a count of the number of times that frame is used. If this is greater than 1 then when we encounter that frame title we need to append the number of that frame, which is given by another count.

Caveats: we write the frame title only on the first slide of a frame. So if the first slide is skipped for some reason, strange things might happen. Similarly, it is possible to use overlays to change the title from one slide to another. This makes no check for that and might go horribly wrong if this is done.

Here's the code, it was an adaptation of the code in my answer to Re-using the title of the previous Beamer slide:

\documentclass{beamer}
%\url{http://tex.stackexchange.com/q/66274/86}
%\url{http://tex.stackexchange.com/q/65975/86}
\makeatletter
\def\beamer@checkframetitle{%
\begingroup
  \edef\temp{%
    \endgroup
    \noexpand\frametitle
    [\unexpanded\expandafter{\beamer@savedshortframetitle}]%
    {\unexpanded\expandafter{\beamer@savedframetitle}}%
  }
\temp
\@ifnextchar\bgroup\beamer@inlineframetitle{}}

\addtobeamertemplate{frametitle}{}{%
\only<1>{\immediate\write\@auxout{\string\beamer@countframes{max}{\beamer@frametitle}}}%
}

\long\def\beamer@@frametitle[#1]#2{%
  \beamer@ifempty{#2}{}{%
    \@ifundefined{beamer@framecount@max@#2}{%
    \gdef\insertframetitle{{#2\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi}}%
    }{%
    \ifnum\csname beamer@framecount@max@#2\endcsname>1\relax
    \beamer@countframes{cur}{#2}%
    \gdef\insertframetitle{{#2\beamer@autobreakcount\csname beamer@framecount@cur@#2\endcsname\relax{}\space\usebeamertemplate*{frametitle continuation}}}%
    \else
    \gdef\insertframetitle{{#2\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi}}%
    \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

\def\beamer@countframes#1#2{%
  \@ifundefined{beamer@framecount@#1@#2}{%
    \expandafter\gdef\csname beamer@framecount@#1@#2\endcsname{1}%
  }{%
    \@tempcnta\csname beamer@framecount@#1@#2\endcsname\relax%
    \advance\@tempcnta by 1\relax
    \expandafter\xdef\csname beamer@framecount@#1@#2\endcsname{\the\@tempcnta}%
  }%
}

\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}
\begin{frame}{The Third Frame Title}
But not the third frame
\end{frame}
\begin{frame}{The Fourth Frame Title}
Another title,\pause another frame.
\end{frame}
\end{document}

Result:

Auto-number of beamer frames with the same name

share|improve this answer
    
Andrew, thanks for the effort and time to come up with this solution! Would it be possible for you to add some comments to the code above? Apart from using it, I'd like to learn something from it as well :) –  Ailurus Aug 17 '12 at 20:56

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.