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.

Using the package gb4e for linguists in the beamer environment in combination with frame splitting commands \pause or environments overprint, I face the following problem: The number are "jumping" strangely.

The same happens when I use the beispiel environment (see below) in combination with \pause command or the splitting environments. Therefore, I believe, that it is a general problem of a certain kind of counters with these commands and environments. My question is: How do I avoid this odd jumping behaviour? (In regard to the gb4e based environment the answer is more important. The other I just provided to show the general nature of this problem. However, I would like to see a possible solution here as well, to get a deeper understanding of LaTeX.)

\documentclass{beamer}
%\usetheme{Bergen}

\usepackage[ngerman]{babel} %dt. Silbentrennung
\usepackage[applemac]{inputenc}

  \usepackage{gb4e}

  \newcounter{beispz} %Beispiele mit durchgehender Nummerierung und  in italics
\newenvironment{beispiel}
    {\stepcounter{beispz}
    \begin{enumerate}\item[(\arabic{beispz})]\linespread{1}\em}
    {\end{enumerate}} %\label{\stepcounter{beispz}}

\begin{document}

\begin{frame}
\begin{exe}
\ex Du bist mir ein feiner Freund!\pause
\ex A: Wie viele Einwohner hat New York?
\end{exe}
\end{frame}

\begin{frame}
\begin{beispiel} asdfas\end{beispiel} \pause

\begin{beispiel} hand\end{beispiel}
\end{frame}

\end{document}

Remark: Werner gave a possible solution. It involves manually setting the counter number by adding \addtocounter{}{+previous no} in front of the counting environment and using \addtocounter{}{-last no} in the end of the environment (see below). For example:

\begin{beispiel}a\end{beispiel}\pause \begin{beispiel}b\end{beispiel}\addtocounter{beispz}{-2}\pause.

It works. But

As you can imagine, it involves a great deal of manual work if you are preparing a larger document. Therefore, I would like to ask if there is anyone out there who knows a solution that needs considerably less effort.

share|improve this question
add comment

2 Answers

beamer does a lot of legwork in the background when you use the \pause command. In fact, to maintain the correct vertical/horizontal alignment, it still has to process whatever is presented after \pause, even though it is not printed on that particular slide. As such, it also parses the contents, incrementing counters as it going along. The following exaggerates this problem, but acts as a prime example:

Counter problems in beamer with \pause

\documentclass{beamer}% http://ctan.org/pkg/beamer
\begin{document}
\newcounter{beispz} %Beispiele mit durchgehender Nummerierung und  in italics
\newenvironment{beispiel}
  {\stepcounter{beispz}
   \begin{enumerate}\item[(\arabic{beispz})]\linespread{1}\em}
  {\end{enumerate}} %\label{\stepcounter{beispz}}

\begin{document}
\begin{frame}
\begin{beispiel} abc\end{beispiel} \pause
\begin{beispiel} def\end{beispiel}
\begin{beispiel} ghi\end{beispiel}
\begin{beispiel} jkl\end{beispiel}
\end{frame}

\end{document}​

Slide 1 only sets (1) abc with the correct counter. However, it also processes the remaining beispiel environment on slide 1, leaving the beispz counter at 4 at the end of slide 1. Then it reprocesses the frame to produce the second slide, this time starting with (5) abc, as expected.

To avoid this, you have to know which counters are being manipulated and compensate for them via \addtocounter{<cntr>}{<num>}. Here is you example, modified to match with the correct layout:

Correct counters displayed with \pause

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usepackage{gb4e}% http://ctan.org/pkg/gb4e

\newcounter{beispz} %Beispiele mit durchgehender Nummerierung und  in italics
\newenvironment{beispiel}
  {\stepcounter{beispz}
   \begin{enumerate}\item[(\arabic{beispz})]\linespread{1}\em}
  {\end{enumerate}} %\label{\stepcounter{beispz}}

\begin{document}

\begin{frame}
\begin{exe}
  \ex Du bist mir ein feiner Freund!\pause
  \ex A: Wie viele Einwohner hat New York? \addtocounter{xnumi}{-2}
\end{exe}
\end{frame}

\begin{frame}
\begin{beispiel} abc\end{beispiel} \pause
\begin{beispiel} def\end{beispiel} 
\begin{beispiel} ghi\end{beispiel}
\begin{beispiel} jkl\end{beispiel} \addtocounter{beispz}{-4}
\end{frame}
\end{document}​

The counter associated with the first environment exe is xnumi (from looking at the source code of gb4e), while that of the second beispiel is, of course, beispz.

share|improve this answer
    
Hi Werner, It took me some time to apply your solution to more complex presentations. The result works but is not very handy. You have to adjust every new beispiel and/or exe environments manually by first adding the \addtocounter{}{+previous no} and in the end of the environment using \addtocounter{}{-last no}. For example: \begin{beispiel}a\end{beispiel}\pause \begin{beispiel}b\end{beispiel}\addtocounter{beispz}{-2}\pause \addtocounter{beispz}{+2} \begin{beispiel}c\end{beispiel}\addtocounter{beispz}{-3}\pause. Adjustments in longer documents might be very unpleasant. –  Philip Mar 1 '12 at 8:06
    
@Philip: This is fundamental to beamer. Not only that, in general, you could be in any environment and requesting a counter adjustment - something that beamer would not be able to "just pick up". So, manual intervention seems the only alternative. –  Werner Mar 1 '12 at 21:12
    
For me - as not trained in computer science - it seems strange that it has to be done by manual adjustments. Because other counting environments like enumerate aren´t affected by commands like \pause. Initially, I thought/imagined that this environments come with a different kind of counter or that this environments are processed by latex on a more fundamental level, maybe before beamer splits the frames in different slides. So I was hoping for a adjustments in these areas. –  Philip Mar 2 '12 at 12:38
add comment
up vote 0 down vote accepted

I found the right in a post Re: Ling-TeX: Beamer, gb4e example numbering and the \pause command by Alan Munn. By adding \resetcounteronoverlays{exx}to the preamble, it can be achieved.

share|improve this answer
add comment

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.