4

I used the following piece of code to put a box around each page in my report

\documentclass[12pt,a4paper,oneside,final,times]{report}

\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{empty}}} 
\usepackage{graphicx}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\usepackage{fancyheadings}
\usepackage{fancybox}
\usepackage{setspace}
\usepackage{fixltx2e}
\usepackage{amssymb,amsmath}
\usepackage{pgf}
\usepackage{pgfpages}
%\usepackage{fncychap}

\usepackage{lipsum,titletoc}
\usepackage{titlesec}
\usepackage{simplemargins}
\pgfpagesdeclarelayout{boxed}
{
\edef\pgfpageoptionborder{0pt}
}
{
\pgfpagesphysicalpageoptions
{%
logical pages=1,%
}
\pgfpageslogicalpageoptions{1}
{
border code=\pgfsetlinewidth{2pt}\pgfstroke,%
border shrink=\pgfpageoptionborder,%
resized width=.90\pgfphysicalwidth,%
resized height=.85\pgfphysicalheight,%
center=\pgfpoint{.53\pgfphysicalwidth}{.5\pgfphysicalheight}%
}%
}

\pgfpagesuselayout{boxed}
\pagestyle{fancy}

but this is causing my page numbers to be different from that of the toc. To be specific, page numbers in toc=page number on page +1.

Any solution for this, please? The code is borrowed from this answer by Andrew Stacey

4
  • 3
    You need to give more information: this code is useless without knowing the class used, for example, and all the packages used.
    – egreg
    Commented Jan 16, 2012 at 19:01
  • @egreg am sorry. I've edited my question.
    – Dibu John
    Commented Jan 16, 2012 at 19:16
  • 3
    Thanks for adding the information. To make your question fit good question style here on tex.sx even better, it'd be nice if you could alter your example so that it only contains what's necessary to reproduce your problem, but everything that's necessary for other users to be able to copy and compile your code in order to see the problem. This is called a minimal working example (MWE). Two things you'll have to do is removing some packages and adding a document body of a few pages. You'll be more likely to get an answer if you provide such code.
    – doncherry
    Commented Jan 16, 2012 at 21:54
  • Well, that's what you get if you use dodgy code from some no-good halfwit who doesn't know his \expandafter from his \romannumeral. Caveat TeXtor and all that. Commented Jan 17, 2012 at 9:31

1 Answer 1

5

On page 515 of the PGF manual (which also documents pgfpages, I'm looking at the version for PGF2.10) it says:

Another word of caution: using pgfpages will produce wrong page numbers in the .aux file. The reason is that TeX instantiates the page numbers when writing an .aux file only when the physical page is shipped out. Fortunately, this problem is easy to fix: First, typeset our file normally without using the \pgfpagesuselayout command (just put the comment marker % before it)[.] Then, rerun TeX with the \pgfpagesuselayout command included and add the command \nofiles. This command ensures that the .aux file is not modified, which is exactly what you want.

I just tried it with the example in Peter's answer and it worked:

\documentclass{report}

\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{empty}}} 

\usepackage{fancyheadings}
\usepackage{pgf}
\usepackage{pgfpages}

\usepackage{lipsum}
\usepackage{titletoc}

\pgfpagesdeclarelayout{boxed}
{
\edef\pgfpageoptionborder{0pt}
}
{
\pgfpagesphysicalpageoptions
{%
logical pages=1
}
\pgfpageslogicalpageoptions{1}
{%
border code=\pgfsetlinewidth{2pt}\pgfstroke,%
border shrink=\pgfpageoptionborder,%
resized width=.90\pgfphysicalwidth,%
resized height=.85\pgfphysicalheight,%
center=\pgfpoint{.53\pgfphysicalwidth}{.5\pgfphysicalheight}%
}%
}

% uncomment both of the next two lines on the final run through
%\pgfpagesuselayout{boxed}
%\nofiles
\pagestyle{fancy}

\begin{document}
\tableofcontents
\clearpage
\section{One}
\lipsum[1-12]
\section{Two}
\lipsum[12-25]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .