6

I'm creating a handout for my beamer presentation using the 4 on 1 layout for pgfpages. I'd like each physical page (which contains four "pages" of the handout) to have a page number bottom centre of the page. Adding \pagestyle{plain} puts a page number on every logical page (thus, four page numbers per physical page).

Is there a simple solution to this?

It hardly seems worth providing an MWE, but here goes:

\documentclass{beamer}
\usepackage{pgfpages}
\pgfuselayout{4 on 1}[landscape]
\begin{document}
\frame{foo}
\frame{bar}
\frame{baz}
\frame{bazbarfoo}
\end{document}

I'd like a page number bottom centre of the page.

  • 2
    Can you provide some code to play with please? – user11232 Jun 13 '14 at 12:39
  • 2
    If you don't mind a solution with pdfpages instead of (or after) using handout+pgfpages, take a look at Actual page number (and total number of pages) in the handout – Ignasi Jun 13 '14 at 14:28
  • 1
    you can try \makeatletter \def\pgfsys@endpicture{% \makebox[\pgfphysicalwidth]{\the\numexpr\value{page}/4\relax} }\makeatother – touhami Oct 30 '15 at 13:10
  • @touhami Why don't you turn this into an answer? – Seamus Nov 5 '15 at 14:53
  • @Seamus Sorry, I was offline. – touhami Nov 9 '15 at 15:54
2

Here is a solution .\rule[-.5cm]{0pt}{0pt} to add some extra vertical space below the page number.

\documentclass{beamer}
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,landscape]
\makeatletter \def\pgfsys@endpicture{%
\makebox[\pgfphysicalwidth]{\the\numexpr\value{page}/4\relax}\rule[-.5cm]{0pt}{0pt}}
\makeatother
\begin{document}
\frame{foo}
\frame{bar}
\frame{baz}
\frame{bazbarfoo}
\end{document}
  • Having tried this code, I found at least four things wrong with it! Since \thenumexpr rounds to the nearest integer, this way of calculating the page number only works for 4 on 1 (and, as it happens, three slides to a page). pgfsys@endpicture is called by PGF graphics generally so this may disrupt the spacing anywhere else PGF is used. And deleting the existing contents of pgfsys@endpicture causes problems when using XeLaTeX, for example. Depending on the document, the rule may push content off the top of the page. I have provided an alternative answer that addresses these problems. – Alex Ball Sep 3 '18 at 14:54
2

The problem with redefining \pgfsys@endpicture is that this is called at the end of each PGF graphic you use (including the six tiny navigation symbols on each beamer slide). It is also used to hold special instructions when you use certain drivers; so if you use XeLaTeX you will find the slides are not positioned correctly on the second and later pages. Best to leave that alone.

To get the fewest nasty surprises, you need to inject your code for writing the page numbers directly into the pgfpages output routine. The \patchcmd command from etoolbox works for this.

While using a \makebox directly works, it also takes up vertical space, so the tops of your slides on the first row may get pushed off the page. The code below uses the same technique as pgfpages for positioning the number on the page without taking up room. To move it around, change the distances in the \pgfpoint (measuring from the bottom left corner):

\documentclass{beamer}
\usepackage{etoolbox,pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,landscape]
\newcounter{physicalpage}
\makeatletter
\patchcmd{\pgfpages@buildshipoutbox}{%
  \pgfsys@endpicture
}{%
  \stepcounter{physicalpage}%
  \setbox0\vbox{\makebox[0pt][c]{\arabic{physicalpage}}}%
  \pgfsys@beginscope
  \pgflowlevel{\pgftransformshift{\pgfpoint{.5\pgfphysicalwidth}{5mm}}}%
  \wd0=0pt%
  \dp0=-\ht0%
  \pgfsys@hbox0%
  \pgfsys@endscope
  \pgfsys@endpicture
}{}{}
\makeatother
\begin{document}
\frame{foo}
\frame{bar}
\frame{baz}
\frame{bazbarfoo}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.