3

I like to take bits of, often older texts, and place it in a nice looking PDF/LaTeX file. Often several pages of the older text fits on to one PDF letter page. I would like to find a way to make the text flow freely on the PDF pages, but the page numbering on the PDF to match the original text. I have previously used a method with an additional page number, from the original work, in the margin, but I wonder if there is a way to play more loosely with the LaTeX page numbering?

I've tried to illustrate what I am looking for below.

+------------------------+    +------------------------+    +------------------------+
|  A ........... 1       |    |                        |    |                        |
|  B ........... 4       |    | \section{C}            |    |                        |
|  C ........... 5       |    | \setcounter{page}{6}   |    |                        |
|  D ........... 6       |    |                        |    | \section{F}            |
|  E ........... 7       |    |                        |    |  Lorem ipsum dolor     |
|  F ........... 8       |    | \section{D}            |    |  dolor sit amet.       |
|                        |    |                        |    |  Duis in sodales,      |
| \section{A}            |    | \setcounter{page}{7}   |    |  vulputate ligula.     |
| \setcounter{page}{4}   |    | \section{E}            |    |                        |
| \section{B}            |    |                        |    |                        |
|          1/4           |    |         5/6/7          |    |           8            |
+------------------------+    +------------------------+    +------------------------+
2
  • Would you mind elaborating a bit what do you mean by `play more loosely'?
    – Masroor
    May 2, 2014 at 9:37
  • @MMA, Thank you for taking the time to respond to my question. I would like to have several page numbers on each PDF and be able to, somehow, control where a new page begins, like in my mini illustration.
    – Eric Fail
    May 2, 2014 at 9:39

1 Answer 1

2

I don't know how robust this is, but here's an implementation that might work for you:

enter image description here

\documentclass{article}
\usepackage[paper=a6paper]{geometry}% Just for this example
\usepackage{fancyhdr, afterpage}
\newcommand{\newpagenumber}{\thepage}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\newpagenumber}

\makeatletter
\let\old@addcontentsline\addcontentsline% Store original \addcontentsline
\newcommand{\setnextsectionpage}[1]{% \setnextsectionpage{<new page number>}
  \afterpage{% Adjust things after this page
    \setcounter{page}{\numexpr#1+1}% Correct page number
    \gdef\newpagenumber{\thepage}}% Restore single page number as footer
  \g@addto@macro{\newpagenumber}{/#1}% Append new (false) page number
  \renewcommand{\addcontentsline}[3]{%
    % Falsify \thepage to be a page that is specifically set
    \addtocontents{##1}{\protect\contentsline{##2}{##3}{#1}}%
    \let\addcontentsline\old@addcontentsline}% Restore default behaviour
}
\makeatother

\begin{document}

\tableofcontents% Page 1

\section{First section}% Page 1
\setnextsectionpage{4}
\section{Second section}% Page 4

\clearpage
\section{Third section}% Page 5

\setnextsectionpage{6}
\section{Fourth section}% Page 6

\setnextsectionpage{7}
\section{Fifth section}% Page 7

\clearpage
\section{Last section}% Page 8

\end{document}

While constructing the page, the page footer is amended with whatever "false pages" you have on the current page. Then afterpage is used to correct the page number and restore the default \thepage footer.

A slight modification to \addcontentsline allows us to insert whatever page number we decide, as designated by \setnextsectionpage{<new page number>}.

You must log in to answer this question.

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