# Beamer handout: Problem when creating border around frames

I am trying to create handouts from a Beamer presentation. I want multiple frames to be on each sheet of printed paper, and I want the frames to have a border, say a border made with a thin line. To save ink, I do not want a shaded background.

I have two problems that need solved. First, how do I create a border for the frames in the handout? The portion of the code below marked Border creates a border, but it also creates a border for frames that do not exist. The portion of the code below marked Prints 8 on 1 allows me to put eight frames one each sheet of paper, but part of the top frames do not print (they're cut off). How can this be fixed without changing printer settings?

\documentclass[10pt,handout,mathserif]{beamer}

\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{graphics}
\usepackage{color}
\usepackage{framed}
\usepackage{amsthm, array}
\usepackage{yhmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfpages}
%
% Prints 8 on 1
\pgfpagesuselayout{8 on 1}[letterpaper,border shrink=1mm]
%
%
% Border
\pgfpageslogicalpageoptions{1}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{2}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{3}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{4}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{5}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{6}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{7}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{8}{border code=\pgfusepath{stroke}}
%
%
\begin{document}

%Stuff goes here.

\end{document}

-
I accidentally posted a rough draft of my question. I fixed the problem involving the top frames being cut off (I changed border shrink=1mm to border shrink=5mm). I'm still stuck with the border problem. –  Nathan Apr 26 '12 at 21:55
Can you try this one? \documentclass[10pt,handout,mathserif]{beamer} \usepackage{amsmath,amssymb,amsfonts,amsthm} \usepackage{graphicx} \usepackage{color} \usepackage{framed} \usepackage{amsthm, array} \usepackage{yhmath} \usepackage{tikz} \usepackage{pgfplots} \usepackage{pgfpages} \setbeamertemplate{background canvas}{ \tikz \draw (current page.north west) rectangle (current page.south east); } \pgfpagesuselayout{8 on 1}[letterpaper,border shrink=1mm] \begin{document} \foreach \x in {1,...,8} {\begin{frame}{Title \x}The frame number \x\end{frame}} \end{document} –  percusse Apr 27 '12 at 1:16
Thank you! I added a few parts of your code to mine, and it did the trick! –  Nathan Apr 27 '12 at 2:22
@percusse: Your comment should probably become an answer. –  Daniel Apr 27 '12 at 6:54
@Daniel Thank you for the reminder, done. –  percusse Apr 27 '12 at 8:50

I use pgfpages for the handouts from my beamer presentations as well. I have a layout that puts a border around each frame as I find that makes it easier to separate the frames visually. I'd also noticed the frame around empty pages at the end but hadn't thought to try to fix it until now (though I agree that it doesn't look great to have them there, particularly as the borders are a bit thicker - because of the implementation). However, someone asking is a great motivation for getting rid of such annoyances. So here's a solution.

I use a custom layout that puts a border around each page and allows for shrinkage of the pages. Before putting the border round, though, it tests to see if there is actually anything on the page. If not, it doesn't do the border.

\documentclass[handout]{beamer}

\usepackage{pgffor}

\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{8 on 1 boxed}
{
\edef\pgfpageoptionheight{\the\paperheight}
\edef\pgfpageoptionwidth{\the\paperwidth}
\edef\pgfpageoptionborder{0pt}
}
{
\pgfpagesphysicalpageoptions
{%
logical pages=8,%
physical height=\pgfpageoptionheight,%
physical width=\pgfpageoptionwidth%
}
\pgfpageslogicalpageoptions{1}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.25\pgfphysicalwidth}{.875\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{2}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.75\pgfphysicalwidth}{.875\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{3}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.25\pgfphysicalwidth}{.625\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{4}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.75\pgfphysicalwidth}{.625\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{5}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.25\pgfphysicalwidth}{.375\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{6}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.75\pgfphysicalwidth}{.375\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{7}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.25\pgfphysicalwidth}{.125\pgfphysicalheight}%
}%
\pgfpageslogicalpageoptions{8}
{%
border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
border shrink=\pgfpageoptionborder,%
resized width=.5\pgfphysicalwidth,%
resized height=.5\pgfphysicalheight,%
center=\pgfpoint{.75\pgfphysicalwidth}{.125\pgfphysicalheight}%
}%
}

\IfFileExists{\jobname.aux}{
\pgfpagesuselayout{8 on 1 boxed}[a4paper, border shrink=5mm]
\nofiles
}{}
}

\begin{document}
\foreach \k in {1,...,5} {
\begin{frame}
Frame \k
\end{frame}}
\end{document}


The \IfFileExists bit is to circumvent the interference that Daniel mentions. The first time that this is compiled it does not do the multipage layout but does write to the auxfile. On subsequent runs, it does the multipage layout but doesn't write to the auxfile. This helps with absolute positioning and labels and the like.

Here's the output of the above:

-
The test for the .aux-file to prevent the pgfpages transformations on the first run is pretty neat! –  Daniel Apr 27 '12 at 21:09
@Daniel Thanks. It probably doesn't avoid all of the issues, but it avoids enough for me to not be too bothered about the rest. –  Loop Space Apr 27 '12 at 21:41
@AndrewStacey: If you get chance, I would love to hear any opinions you may have on the 'improvements' I have made to this in tex.stackexchange.com/a/89491. –  cyberSingularity Jan 8 '13 at 3:45

I prefer to not mess with pgfpages and its settings in the presentation source itself, but let an external tool, such as pdfnup, generate the (often various) x-up versions I need with or without borders, distances, scaling:

\documentclass[10pt,handout,onlymath]{beamer}
\usepackage{pgffor}
\usefonttheme{serif}
\begin{document}

\foreach \x in {1,...,7} {\begin{frame}{Title \x}The frame number \x\end{frame}}

\end{document}


If you compile this with:

pdflatex presentation.tex
pdfnup --no-landscape --nup 2x4 --frame true --no-tidy --delta '5mm 5mm' --scale 0.95 presentation.pdf


The result will be a file presentation-nup.pdf that looks as follows:

A plus of this approach is that this does not interfere with other LaTeX packages that also affect the shipout-level. textpos, for instance, is incompatible to pgfpages, even though it is mentioned in the beamer userguide as the way to go for absolute positioning.

-

For handouts, you can either comment out all the theme modifications and stay with the default theme or you can specify what would different cases presentation,article, handout etc. be, using the \mode{} command. For the frame borders, one can use a TikZ rectangle drawn on the border of the special current page node. Here is a simple example:

\documentclass[10pt,handout,onlymath]{beamer}
\usepackage{tikz}
\usepackage{pgfpages}
\usefonttheme{serif}
\setbeamertemplate{background canvas}{
\tikz \draw (current page.north west) rectangle (current page.south east);
}
\pgfpagesuselayout{8 on 1}[letterpaper,border shrink=5mm]
\begin{document}

\foreach \x in {1,...,8} {\begin{frame}{Title \x}The frame number \x\end{frame}}

\end{document}


-