8

I want to prepare an 8 page booklet by imposing the 8 pages, four at a time on a larger sheet of paper. The front side will look like this:

Front of imposition

and the back will look like this:

Back of imposition

When printed correctly, looking through the front to the back will look like this:

Both sides of the printed imposition

Folding: With the back side face up (the '7' at the lower right hand corner) fold the sheet in half left-to-right. The '4' is now at the top, the '5' at the bottom -- fold this in half top-to-bottom. You now have an 8 page booklet -- just trim a little off the bottom and staple. With Werner's code from this answer and pgfpages I can typeset first the FRONT (save the PDF of the front), typeset the BACK, combine the two PDFs into one and then print the two pages onto one sheet back-to-back:

\documentclass{article}

\usepackage[papersize={5.5in,8.5in},margin=0.25in]{geometry}
\usepackage{pgfpages}
\usepackage{tikz}
\usepackage{lipsum,atbegshi,etoolbox,everypage,tikzpagenodes}

\makeatletter
\newcommand{\discardpages}[1]{% \discardpages{<csv list>}
  \xdef\discard@pages{#1}% Store pages to discard
  \AtBeginShipout{% At shipout, decide whether to discard page/not
    \renewcommand*{\do}[1]{% How to handle each page entry in csv list
      \ifnum\value{page}=##1\relax%
        \AtBeginShipoutDiscard% Discard page/not
        \gdef\do####1{}% Do nothing further
      \fi%
    }%
    \expandafter\docsvlist\expandafter{\discard@pages}% Process list of pages to discard
  }%
}
\newif\ifkeeppage
\newcommand{\keeppages}[1]{% \keeppages{<csv list>}
  \xdef\keep@pages{#1}% Store pages to keep
  \AtBeginShipout{% At shipout, decide whether to discard page/not
    \keeppagefalse%
    \renewcommand*{\do}[1]{% How to handle each page entry in csv list
      \ifnum\value{page}=##1\relax%
        \keeppagetrue% Page should be kept
        \gdef\do####1{}% Do nothing further
      \fi%
    }%
    \expandafter\docsvlist\expandafter{\keep@pages}% Process list of pages to keep
    \ifkeeppage\else\AtBeginShipoutDiscard\fi% Discard page/not
  }%
}

\pgfpagesdeclarelayout{Impose4upFront}
{
  \edef\pgfpageoptionheight{\the\paperheight} 
  \edef\pgfpageoptionwidth{\the\paperwidth}
  \edef\pgfpageoptionborder{15pt}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=4,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth%
  }
  \pgfpageslogicalpageoptions{1}%{2} UL
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.25\pgfphysicalwidth}{.75\pgfphysicalheight},
    rotation = 90%
  }%
  \pgfpageslogicalpageoptions{4}%{3} LL
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.25\pgfphysicalwidth}{.25\pgfphysicalheight},%
    rotation=90%
  }%
  \pgfpageslogicalpageoptions{2}%{1} UR
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.75\pgfphysicalwidth}{.75\pgfphysicalheight},%
    rotation = -90%
  }%
  \pgfpageslogicalpageoptions{3}%{4} LR
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.75\pgfphysicalwidth}{.25\pgfphysicalheight},%
    rotation =-90
  }%
}


\pgfpagesdeclarelayout{Impose4upBack}
{
  \edef\pgfpageoptionheight{\the\paperheight} 
  \edef\pgfpageoptionwidth{\the\paperwidth}
  \edef\pgfpageoptionborder{15pt}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=4,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth%
  }
  \pgfpageslogicalpageoptions{2}%{1} UL
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.25\pgfphysicalwidth}{.75\pgfphysicalheight},%
    rotation = 90%
  }%
  \pgfpageslogicalpageoptions{3}%{4} LL
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.25\pgfphysicalwidth}{.25\pgfphysicalheight},%
    rotation=90%
  }%
  \pgfpageslogicalpageoptions{1}%{2} UR
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.75\pgfphysicalwidth}{.75\pgfphysicalheight},%
    rotation = -90%
  }%
  \pgfpageslogicalpageoptions{4}%{3} LR
  {%
    border shrink=\pgfpageoptionborder,%
    resized width=0.5\pgfphysicalheight,%
    resized height=0.5\pgfphysicalwidth,%
    center=\pgfpoint{.75\pgfphysicalwidth}{.25\pgfphysicalheight},%
    rotation =-90%
  }%
}

%% To use, comment-out either pair of the next four lines.
%% Comment-out all four lines to typeset the document normally.

%\keeppages{1,4,5,8}% Front
%\pgfpagesuselayout{Impose4upFront}[physical paper height = 11in, physical paper width = 17in]  
\keeppages{2,3,6,7}% Back
\pgfpagesuselayout{Impose4upBack}[physical paper height = 11in, physical paper width = 17in]

\pagestyle{empty}

%% From everypage.sty:
\AddEverypageHook{%
    \tikz[remember picture,overlay] \draw[thin,red] (current page text area.south west) rectangle (current page text area.north east);%
}

\begin{document}

\centering

\foreach \i in {1,...,8}{%
\resizebox{!}{2in}{\Huge\i}%
\clearpage
}

\end{document}

The question is this: Can this be done in one pass? The manual labor is not great using two passes, but curiosity and laziness urge me to pose the question. I would also point out that pgfpages is extraordinarily useful. Actually, I'm kind of amazed this works at all...

6
  • Related: tex.stackexchange.com/questions/229222/…. But accepted answer also uses two passes. Commented May 21, 2015 at 11:41
  • Very nice indeed! I'll tuck that away for future use!
    – sgmoye
    Commented May 21, 2015 at 12:04
  • What I like about this is that it allows the user to typeset and check the output, and then impose that output -- there can be no possibly unpleasant surprises at the end of the imposition process. That was one of the goals of my approach. You've done the same, but gone at it differently. It is also a pure TeX approach, which is also attractive -- to me, anyway.
    – sgmoye
    Commented May 21, 2015 at 13:12
  • 1
    Thanks. To me, separating the document creation, and the binding arrangement into two distinct phases makes the best sense, precisely because proofing the document-creation phase is much easier before things get rearranged for binding. Commented May 21, 2015 at 13:28
  • 1
    The way I've gone about it, the two phases are actually accomplished in one TeX document: Comment-out all four lines that engage the imposition process, and you are typesetting the original document; uncomment-out the appropriate two lines and the imposition process kicks in.
    – sgmoye
    Commented May 21, 2015 at 13:36

3 Answers 3

5

(Note: this solution uses one pass... but three compilations ! ;-))

Here is a solution using three documents and pdfpages. Compile these three documents in order to get your final booklet.

First document with 8 pages A4 (book-pages.tex):

\documentclass[a4paper]{article}
\begin{document}
\Huge 1 \newpage
\Huge 2 \newpage
\Huge 3 \newpage
\Huge 4 \newpage
\Huge 5 \newpage
\Huge 6 \newpage
\Huge 7 \newpage
\Huge 8
\end{document}

Second document (booklet1.tex):

\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-,signature*=8,landscape,angle=180]{book-pages.pdf}
\end{document}

Third document (booklet2.tex):

\documentclass[a4paper,landscape]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-,signature=2]{booklet1.pdf}
\end{document}
1
  • Of course, this is just the shell script version without the shell script:) It is purely in latex, however, so +1.
    – user30471
    Commented May 21, 2015 at 20:59
2

This is not quite an answer to your question because I am not really giving you a one-step process but it might be of interest because it does give an easy way of doing what you want.

I use pdfpages to do something like this. Rather than doing this by hand, and incorporating pdfpages into the tex file, I use the following bash function to massage the pdf file into shape:

function bookify() {
  texfile=${1/\.*/}
  template="\documentclass[a4paper]{article}\usepackage[final]{pdfpages}\begin{document}"
  template="${template}\includepdf[pages=-,nup=1x2,landscape, signature=4]{$texfile}"
  template="${template}\end{document}"
  /bin/cp $texfile.pdf /tmp
  (cd /tmp && pdflatex -jobname=${texfile}-booklet $template)
}

[That is, bookify essentially runs pdflatex on a file that uses pdfpages to import the original pdfile and then spit it out a new pdf file with the pages doubled up.]

To use this script, type bookify mypdffile.pdf from the command-line. This turns the pdf file mypdffile.pdf into a new pdf file, /tmp/mypdffile-booklet.pdf, that has two logical pages per physical page.

My first thought was to modify my script to produce what you want but it turns out that pdfpages cannot do this in one pass either. A two-step approach is implicit in the following shell function (which calls the first shell function):

function bookified() {
  texfile=${1/\.*/}
  template="\documentclass[a4paper]{article}\usepackage[final]{pdfpages}\begin{document}"
  template="${template}\includepdf[pages=-,nup=1x2,landscape,angle=180,signature=8]{$texfile}"
  template="${template}\end{document}"
  /bin/cp $texfile.pdf /tmp
  (cd /tmp 
  pdflatex -jobname=${texfile}-booklet $template
  /bin/mv ${texfile}-booklet.pdf ${texfile}.pdf
  bookify ${texfile}.pdf)
}

Typing bookified mypffile.pdf will now produce a PDF file /tmp/mypdffile.pdf that has four logical pages to a physical page with the order and orientation that you want. It is still a two-step process, however, the script does all of the work for you, effectively in one step.

Of course, this is not a pure latex solution and, if you don't use bash, you will have to modify appropriately. I also have these bash functions finish by opening the new pdf file in my browser of choice, but I have taken this out because it is OS dependent.

1

pdfpages can certainly do what you want, but it needs a little coaxing; it's not a simple job. I'm not sure about pgfpages. But I've found it difficult to focus on getting my document right when I'm also worrying about imposing the final pages into a booklet or signatures; it clutters up the code a lot.

To avoid this problem, it's often useful to use a separate program; get your document right, then impose the pages into signatures. If you have bash available, consider trying makebook:

makebook

It's a bash script which uses LaTeX and pdfpages, plus the pdftk suite, to impose signatures onto single sheets of paper. I've used it to do pretty much exactly what you want to do here; it removes a lot of the guesswork from the problem. If you try it, use the -v option, along with whatever others you need; it can take a while to run, and -v will give you feedback on what it's doing.

Disclaimer: I'm the author of makebook and have the concomitant high opinion of its functionality and usefulness.

You must log in to answer this question.

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