# How to add background only to title frame and an other only to the last frame?

I just want to add a background only in the beamer title page. I can add it in the .tex as follows:

\setbeamertemplate{background canvas}{
\includegraphics[width=\paperwidth,height=\paperheight]{img/bg-first.pdf}
}


But I don't want the above command in the .tex, but in the .sty files. Thanks for pointing me out how I can add the above command in the .sty files.

Please find the .sty and .tex files below (all of them are quite simple).

## main.sty

\mode<presentation>

\DeclareOptionBeamer{titlepage}{\PassOptionsToPackage{titlepage=#1}{beamertheme-Inner}}
\ProcessOptionsBeamer

\usetheme{Inner}
\usetheme{Outer}

\mode
<all>


## inner.sty

\mode<presentation>

\DeclareOptionBeamer{titlepage}{\def\beamer@titlepage{#1}}

\defbeamertemplate*{titlepage}
{
\begin{center}
\usebeamerfont{title}\inserttitle
\ifx\insertsubtitle\@empty
\else
\vskip2ex
\usebeamerfont{subtitle}\insertsubtitle
\fi
\ifx\insertauthor\@empty
\else
\vskip2ex
\usebeamerfont{author}\insertauthor
\fi
\ifx\insertdate\@empty
\else
\vskip2ex
\usebeamerfont{date}\insertdate%
\fi
\end{center}
\vfill
}


## .tex file

\usetheme{Afnic}

\title{An example theme for \LaTeX{} Beamer}
\author{Sandoche}
\date{February 29, 2012}

\begin{document}

\begin{frame}[plain]
\maketitle
\end{frame}

\AtBeginSection[]
{
\begin{frame}
\frametitle{Outline}
\tableofcontents[currentsection]
\end{frame}
}

-
This is the first time i am hearing about tikz :-). Which tikz code are you referring to ? –  sandoche Mar 1 '12 at 13:02
Yes it didn't work. –  sandoche Mar 1 '12 at 13:16
I changed the title a little … –  Tobi Mar 5 '12 at 14:19

You could check for the frame number:

\setbeamertemplate{background canvas}{%
% On title page
\fi%
}


You may extend this to set thing to all frames except the title:

\setbeamertemplate{background canvas}{%
% On title page
\else%
% Other frames background
\fi%
}


## Extended version

As requested a version that also checks for the last frame. We use etoolbox to enable nested if statements.

\documentclass{beamer}

\usepackage{etoolbox}

\makeatletter

\setbeamertemplate{background canvas}{%
% First frame
\color{red!50}\rule{\paperwidth}{\paperheight}
}{%
% Last frame
\color{orange!50}\rule{\paperwidth}{\paperheight}
}{%
% Other frames
\color{green!50}\rule{\paperwidth}{\paperheight}
}%
}%
}

\makeatother

\begin{document}
\frame{1}

\frame{2}

\frame{3}

\frame{4}
\end{document}


\c@framenumber is the counter of the current frame and \inserttotalframenumber holds the number of the last frame. Certanly one can omit the Other frames part

-
Simply great you are. I have spent nearly one and a half day on this. Just not to disturb you too much, can i do the similar for the last page in the case where the frame number is not known. Thanks again. –  sandoche Mar 1 '12 at 16:01
@sandoche: I’ll have a look at that soon :-) –  Tobi Mar 1 '12 at 18:16
@sandoche: I added an extended version … –  Tobi Mar 1 '12 at 22:22
Sorry for the delay as i was in holidays. Impeccable as the French say. What should i do to give you full marks. –  sandoche Mar 5 '12 at 8:27
@sandoche: I’m not sure what you mean with “full mark” but if my answer answers your question u may upvote it and click the gray check mark to accept my answer. –  Tobi Mar 5 '12 at 12:15

The solution of Tobi has some significant disadvantages. It only works when the titlepage is actually the first frame and also produces a problem when not using the titlepage. A somewhat better solution is using the \AddToShipoutPictureFG* command of eso-pic inside the \setbeamertemplate{title page} command. So the code for the askers inner.sty would be:

\setbeamertemplate{title page}
{
\begin{center}
\usebeamerfont{title}\inserttitle
\ifx\insertsubtitle\@empty
\else
\vskip2ex
\usebeamerfont{subtitle}\insertsubtitle
\fi
\ifx\insertauthor\@empty
\else
\vskip2ex
\usebeamerfont{author}\insertauthor
\fi
\ifx\insertdate\@empty
\else
\vskip2ex
\usebeamerfont{date}\insertdate%
\fi
\end{center}
\vfill
}

-
Hi, I have an issue using \AddToShipoutPictureFG if I display notes on a second screen. The exact command is: \setbeameroption{show notes on second screen=left}. The background is on the note and not on the titlepage now! –  asn Jan 30 at 15:48