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.

First time posting here, very much a novice.

I'm creating some background templates in beamer and I can't figure out why this \ifnum command isn't working properly.

This is the code:

\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\ifnum 1<\thepage<33\relax% Not the title page
    \fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
    \fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
\else% Title page
  \fill[color=MedianBrown] (0,1.2) rectangle (\the\paperwidth,\the\paperheight);
  \fill[color=MedianOrange] (0,0.1) rectangle(3.15,1.1);
  \fill[color=MedianLightBlue] (3.3,0.1) rectangle(\the\paperwidth,1.1); 
\fi
\end{tikzpicture}
}

Basically all I want to do is recreate the background on the first page on all the subsequent pages after #32. However, this only creates the correct background on the first page, the background on pages 33,34,35...etc. are as pages 2-32.

Any help would be great.

share|improve this question
4  
Welcome to TeX.SX! \ifnum only accept one test: \ifnum 1<\thepage<33 will just test if 1<\thepage and consider <33 as part of the “true text”. By the way, 1<\value{page} is better, because it doesn't depend on the current meaning of \thepage (which might not be a number). –  egreg Jul 4 at 12:55
    
@egreg: That's true, but also using \value{page} can not be considered 100% safe. One can always exploit \setcounter{page}{1} somewhere in the presentation (with bad effects of course). –  Claudio Fiandrino Jul 4 at 13:12
    
@ClaudioFiandrino Of course I'm assuming the value of page is not tampered with. –  egreg Jul 4 at 13:19
add comment

2 Answers 2

up vote 13 down vote accepted

The primitive \ifnum accepts only a single test, it's not able to do

1 < \value{page} < 33

Thus you need to make in more steps:

\setbeamertemplate{background}{%
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\ifnum \value{page}=1
  \fill[color=MedianBrown] (0,1.2) rectangle (\the\paperwidth,\the\paperheight);
  \fill[color=MedianOrange] (0,0.1) rectangle(3.15,1.1);
  \fill[color=MedianLightBlue] (3.3,0.1) rectangle(\the\paperwidth,1.1);
\else
  \ifnum\value{page}<33
    \fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
    \fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
  \else
    \fill[color=MedianBrown] (0,1.2) rectangle (\the\paperwidth,\the\paperheight);
    \fill[color=MedianOrange] (0,0.1) rectangle(3.15,1.1);
    \fill[color=MedianLightBlue] (3.3,0.1) rectangle(\the\paperwidth,1.1);
  \fi
\fi
\end{tikzpicture}%
}

Note that it's better to use \value{page} instead of \thepage, because the former refers to the “abstract” counter value, not to any representation thereof.

share|improve this answer
    
Thanks for the help! –  Juggler Jul 7 at 7:55
add comment

Pgfmath offers also boolean compositions hence you can fall back to it and test the resulting boolean with \ifnum;

\setbeamertemplate{background}{%
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\pgfmathparse{\value{page}<33 &&\value{page}>1?int(1):int(0)}
\ifnum\pgfmathresult>0\relax% Not the title page
    \fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
    \fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
\else% Title page
  \fill[color=MedianBrown] (0,1.2) rectangle (\the\paperwidth,\the\paperheight);
  \fill[color=MedianOrange] (0,0.1) rectangle(3.15,1.1);
  \fill[color=MedianLightBlue] (3.3,0.1) rectangle(\the\paperwidth,1.1); 
\fi
\end{tikzpicture}%
}
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.