# Change in the header for the handout

I am running into a weird problem. When I run my code in beamer mode, the logo that I use in each slide (in the right top corner) stays there and does not move. When I try to make handouts, the logo changes its position and goes to a weird place. Any thought? Help? Here is my MWE:

\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer}
%\documentclass[11 pt, handout,xcolor=pdftex,x11names,table]{beamer}
\usepackage{pgf, pgfpages, pgfplots}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{color}
\usepackage{pdfpages}
\usepackage[absolute,overlay]{textpos}
\mode<presentation>
{
\usecolortheme{orchid}
\usecolortheme{whale}
}
\title[]{Hi}
\author {\Large{\emph{Me}}}
\date[\today]{\today \\  \\
\includegraphics[height=1.5cm]{logo.eps}}
\makeatletter
\def\strokeifnotempty{%
\expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
\let\@next=\relax
\else
\let\@next=\pgfstroke
\fi
\@next%
}
\makeatother
\mode<handout>
{
\usepackage{pgf}
\usepackage{pgfpages}
\pgfpagesdeclarelayout{2 on 1 boxed}
{
\edef\pgfpageoptionheight{\the\paperheight}
\edef\pgfpageoptionwidth{\the\paperwidth}
\edef\pgfpageoptionborder{10pt}
}
{
\pgfpagesphysicalpageoptions
{%
logical pages=2,%
physical height=\pgfpageoptionheight,%
physical width=\pgfpageoptionwidth%
}
\pgfpageslogicalpageoptions{2}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=0.85\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{0.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{1}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=0.85\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
}%
}
\IfFileExists{\jobname.aux}{
\pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
\nofiles
}{}
}
\begin{document}
{
\begin{frame}
\titlepage
\end{frame}
}
\begin{textblock*}{100mm}(0.84\textwidth,0.07cm)
\includegraphics[height=0.8cm]{logo.eps}
\end{textblock*}
}
\begin{frame}
\frametitle{Hi}
HEY
\end{frame}
\begin{frame}
\frametitle{Material?}
My book
\end{frame}
\begin{frame}
\frametitle{Course Website}
Nothing
\end{frame}
\end{document}


I also tried to include the logo file; but .eps format is not accepted and I could not upload it...

I need to add that, if you want to run it in handout mode, please make the first line comment and uncomment the second line.

-
–  cyberSingularity Jan 5 '13 at 14:29
@cyberSingularity: Thank you. Can you please, somehow, make it an answer then I can accept it? –  N Nik Jan 5 '13 at 14:45
@NNik If your question is the same as a previous one, we'll close this as a dupe. Let me know if that's what you feel is appropriate, and I'll do it. –  Joseph Wright Jan 5 '13 at 14:51
@JosephWright To the extent that removing the absolute option from the textpos package doesn't really solve the problem (the logo disappears) it's not clear that the linked question is a pure duplicate. –  Alan Munn Jan 5 '13 at 17:08
@JosephWright: I agree with Alan that although this is the same issue with the same cause (and the OP seems happy with the solution in the linked question), the solutions here can relate to what is actually trying to be achieved (logo in the header) whereas the linked question has undisclosed reasons for wanting to use the textpos package. –  cyberSingularity Jan 5 '13 at 18:22

Using textpos with the absolute option causes different output when using pgfpages (it doesn't cause problems with the handout option when not using pgfpages), even when using \nofiles, because the absolute position is in terms of the physical page, not the logical page.

To display a logo in the header, one would ideally use a beamer (outer) theme designed for this purpose, preferably together with the \logo interface that beamer provides, instead of employing textpos. Unfortunately, I am not aware of any existing themes that have the logo where you want it.

The following solution avoids using textpos altogether, and tries to use beamer's \logo feature to some extent (and hopefully still has some sensible behaviour regardless of which template you use), but it is still inelegant:

• One cannot just move the logo position in the sidebar right template, as the frametitle gets placed on top of it. Therefore, we can instead switch off \insertlogo in the sidebar right template...

% prevent the logo from appearing in the usual position on pages
\let\insertlogo\relax% don't worry, the template is executed in a group!
}{}

• ...and put another \insertlogo in the frametitle template, appropriately positioned:

% modify the frametitle template in a generic manner
% so that within it, \insertframetitle also inserts a right aligned box (apparently of no height/width) containing the logo
% elsewhere, \insertframetitle behaves as normal and does not include this logo!
\let\oldinsertframetitle\insertframetitle
\def\insertframetitle{\makebox[\textwidth][l]{\oldinsertframetitle}\vbox to 0pt{\vtop{\vskip-0.6cm\makebox[0pt][r]{\insertlogo}}}}%
}%
{}%


If you want the horizontal position to be more like as in your original example, add \hspace{1.5cm} after \insertlogo in the \def\insertframetitle.

Note that the positioning method for the logo in the frame title is not great.

I have also placed this in the context of your MWE, which I have also made a few changes to:

1. Used \titlegraphic instead of your previous hack for setting the logo on the title page.
2. Used example-image-a from the mwe package, as I (and others) do not have the logo you were using.
3. Reduced some of the pgfpages layout code you were using. Rather than essentially copying the original 2 on 1 definition just to add a border, I just declared a layout that loaded the original definition. Note that it is not identical to your version, however.
4. Tried to improve the \nofiles issue, by ensuring that at least 2 proper LaTeX runs occur before invoking pgfpages and \nofiles. Now the LastPage counters in the footers are correct. (Of course, whether or not you experience any issue depends on how many times you compile the file without the handout mode.) This is why my code is so long...
5. Replaced one of the \documentclass lines with a \PassOptionsToClass line, as it makes the difference clearer and it is only one line to comment/uncomment instead of two.
6. Removed a few things that were unneeded.
7. Moved the frametitle patching to the preamble.

Full code:

\PassOptionsToClass{handout}{beamer}% just comment out this line to disable handout mode
\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{mwe}% for example-image-a (requiring the package helps the package manager)

\mode<presentation>
{
\usecolortheme{orchid}
\usecolortheme{whale}
}
\title{Hi}
\author{Me}
\date{\today}

% use the \logo and \titlegraphic facilities provided by beamer
\logo{\includegraphics[height=0.8cm]{example-image-a}}
\titlegraphic{\includegraphics[height=1.5cm]{example-image-a}}

% prevent the logo from appearing in the usual position on pages
\let\insertlogo\relax% don't worry, the template is executed in a group!
}{}
% modify the frametitle template in a generic manner
% so that within it, \insertframetitle also inserts a right aligned box (apparently of no height/width) containing the logo
% elsewhere, \insertframetitle behaves as normal and does not include this logo!
\let\oldinsertframetitle\insertframetitle
\def\insertframetitle{\makebox[\textwidth][l]{\oldinsertframetitle}\vbox to 0pt{\vtop{\vskip-0.6cm\makebox[0pt][r]{\insertlogo}}}}%
}%
{}%

\makeatletter

\mode<handout>
{
% based on [Beamer handout: Problem when creating border around frames](http://tex.stackexchange.com/a/53606)
\def\pgfpagesborderstrokeifnotempty{%
\expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
\else
\expandafter\pgfstroke
\fi
}

% count number of LaTeX runs to attempt to guess if we can activate pgfpages and execute \nofiles
\newcommand*{\IfRanMoreThan}[1]{\ifnum\value{counttexrunsforpgfpages}>#1\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}%

% following mostly borrowed from counttexruns.sty
% can't just use that package directly;
% have to split because we don't always want to update the counter (breaks latexmk)
% when editing the file, should also delete \jobname.\counttexrunsforpgfpages@extension to allow recompilation enough times
\newcounter{counttexrunsforpgfpages}%
\newwrite\@counttexrunsforpgfpagesfile
\def\counttexrunsforpgfpages@extension{pgfpages.ctr}%
\IfFileExists{\jobname.\counttexrunsforpgfpages@extension}{%
\immediate\openin\@counttexrunsforpgfpagesfile=\jobname.\counttexrunsforpgfpages@extension
\immediate\closein\@counttexrunsforpgfpagesfile
\setcounter{counttexrunsforpgfpages}{\@counttexrunsforpgfpages}
}{}%
\stepcounter{counttexrunsforpgfpages}%

\IfRanMoreThan{2}{%hope file gets compiled enough times without pgfpages being active (only need to ensure the lines \pgfpagesuselayout and \nofiles are in this block, but save time by not loading the packages if not needed in current run)
\usepackage{pgf}
\usepackage{pgfpages}
% extend the default definition of the '2 on 1' layout to add a border to each logical page,
% without having to copy the whole of the original layout definition
\pgfpagesdeclarelayout{2 on 1 boxed}%
{%
\pgfpagesuselayout{2 on 1}%
\edef\pgfpageoptionborder{10pt}%change default value for border shrink
}%
{%
\pgfpageslogicalpageoptions{1}{%
border code=\pgfsetlinewidth{2pt}\pgfpagesborderstrokeifnotempty,
resized width=0.85\pgfphysicalwidth,
}%
\pgfpageslogicalpageoptions{2}{%
border code=\pgfsetlinewidth{2pt}\pgfpagesborderstrokeifnotempty,
resized width=0.85\pgfphysicalwidth,
}%
}%
\pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
\nofiles
}{%
% save the number of runs to the file! also adjusted from counttexruns.sty
\immediate\openout\@counttexrunsforpgfpagesfile=\jobname.\counttexrunsforpgfpages@extension
\catcode\%=11\relax
\immediate\write\@counttexrunsforpgfpagesfile{%% This file
'\jobname.\counttexrunsforpgfpages@extension' was not really generated by the package counttexruns}
\catcode\%=14\relax
\immediate\write\@counttexrunsforpgfpagesfile{\arabic{counttexrunsforpgfpages}}
\immediate\closeout\@counttexrunsforpgfpagesfile
}%
}% end \mode<handout>
\makeatother

\begin{document}

% \titlepage doesn't use \frametitle, so the logo only appears there in the \titlegraphic
\begin{frame}
\titlepage
\end{frame}

\begin{frame}
\frametitle{Hi}
HEY
\end{frame}
\begin{frame}
\frametitle{Material?}
My book
\end{frame}
\begin{frame}
\frametitle{Course Website}
Nothing
\end{frame}

\end{document}


-
Is it possible to include please some comments explaining what you are doing in your good MWE? For example for the part with \makeatletter. I think that would help readers to understand better what is going on ... –  Kurt Jan 8 '13 at 0:36
@Kurt: I have extended my answer (and you may feel it no longer qualifies as 'good'), but note that the original \makeatletter part was provided by the OP. –  cyberSingularity Jan 8 '13 at 3:43

This works: Just remove absolute option for textpos and re-tune the logo position:

%\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer}
\documentclass[11 pt, handout,x11names,table]{beamer}
\usepackage{pgf, pgfpages, pgfplots}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
%\usepackage{color}
%\usepackage{pdfpages}
\usepackage[overlay]{textpos}
\mode<presentation>
{
\usecolortheme{orchid}
\usecolortheme{whale}
}
\title[]{Hi}
\author {\Large{\emph{Me}}}
\date[\today]{\today \\  \\
\includegraphics[height=1.5cm]{example-image}}
\makeatletter
\def\strokeifnotempty{%
\expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
\let\@next=\relax
\else
\let\@next=\pgfstroke
\fi
\@next%
}
\makeatother
\mode<handout>
{
\usepackage{pgf}
\usepackage{pgfpages}
\pgfpagesdeclarelayout{2 on 1 boxed}
{
\edef\pgfpageoptionheight{\the\paperheight}
\edef\pgfpageoptionwidth{\the\paperwidth}
\edef\pgfpageoptionborder{10pt}
}
{
\pgfpagesphysicalpageoptions
{%
logical pages=2,%
physical height=\pgfpageoptionheight,%
physical width=\pgfpageoptionwidth%
}
\pgfpageslogicalpageoptions{2}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=0.85\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{0.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{1}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=0.85\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
}%
}
\IfFileExists{\jobname.aux}{
\pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
\nofiles
}{}
}
\begin{document}
{
\begin{frame}
\titlepage
\end{frame}
}
\begin{textblock*}{100mm}(0.84\textwidth,-0.9cm)
\includegraphics[height=0.8cm]{example-image}
\end{textblock*}
}
\begin{frame}
\frametitle{Hi}
HEY
\end{frame}
\begin{frame}
\frametitle{Material?}
My book
\end{frame}
\begin{frame}
\frametitle{Course Website}
Nothing
\end{frame}
\end{document}

-
Thank you for the answer. Your solution works as well :) Thanks –  N Nik Jan 6 '13 at 1:53