2

There are several answers about "learning cards" here on Stackexchange, pointing to several solutions, but this particular part of it is not my problem. I already designed them, created them (DIN A 6) with front and back and got a PDF with consecutive pages "front : back" of each index card.

One index card with front and back side

Now I'm going to print them, and right here my problem starts.

The idea is to arrange 2x2 of those cards on an DIN A 4 paper, so I can print them with usual hardware. This is possible by using the pdfpages package postprocessing the first PDF named "cards.pdf", creating a second one:

\documentclass[landscape]{scrartcl}
\usepackage{pdfpages}

\begin{document}
\includepdf[frame, pages={1, 3, 5, 7}, nup=2x2]{cards.pdf}
\includepdf[frame, pages={6, 8, 2, 4}, nup=2x2]{cards.pdf}
\end{document}

Index cards 2x2

That works fine, but as you may have realized, I have to specify the page numbers manually, which may be a difficult task in case of a huge number of cards. There must be an easier way to achieve this.

And that's my question: How can I print those index cards two-sided with multiple cards per page in a way, that right behind the front side of one card its back side fits on the very back of the printed paper?

3

Longer post

I'm using double flopping/reflecting method. It requires several steps, please use pdflatex or lualatex. The example below could be slightly modified to be used with xelatex, please see How to automatically output page order to print 8 pages of a booklet on a single sheet of Letter paper?, where I used \XeTeXpdfpagecount instead of \pdfximage and \pdflastximagepages. Then all three major LaTeX engines could be run.

Step 1: The materials to be printed

I am emulating 32 unrelated business cards with both sides typesetted. We will try to print 4x4 of them on A4 papers, duplex and long edge printing. I enclose the TeX code (mal-pdf-part1.tex) and a preview of the first eight pages (of 64).

% run: any LaTeX engine mal-pdf-part1.tex
\documentclass[a4paper,landscape]{article}
\paperwidth=0.25\paperwidth
\paperheight=0.25\paperheight
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\usepackage{tikz}
\begin{document}
\newcount\malc 
\malc=0
\loop
\advance\malc by 1
\foreach \mcolor/\mside in {green/front,blue/back} {%
\newpage
\pagecolor{\mcolor}%
\begin{tikzpicture}[remember picture, overlay]
\node[font=\bfseries,scale=10,yshift=0.8mm] at (current page) {\the\malc}; % front side
\node[font=\bfseries,scale=4,yshift=-4mm] at (current page) {\mside{} side}; % back side
\end{tikzpicture}%
}% End of \foreach...
\ifnum\malc<32\repeat % E.g. a number of business cards...
\end{document}

mwe, part 1


Step 2: Rearranging the odd pages (the front/recto pages)

Generally speaking, we only need to select them (step 2a) and use basic nup=4x4 in the pdfpages package (step 2b). I enclose both TeX files and a preview of the PDF files. This is the mal-pdf-part2a.tex file (preview consists of 8 pages of 32):

% run: pdflatex or lualatex mal-pdf-part2a.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part1.pdf}
\pdfximage{\malfile}
\newcount\malc \malc=0
\loop
\advance\malc by 1%
\ifnum\malc<\pdflastximagepages
  \ifodd\malc\else
  \includepdf[fitpaper,pages={\the\malc},angle=90]{\malfile}
  \fi
\repeat
\end{document}

mwe, step 2a

And this is the mal-pdf-part2b.tex file:

% run: pdflatex or lualatex mal-pdf-part2b.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},nup=4x4,frame]{mal-pdf-part2a.pdf}
\end{document}

mwe, step 2b


Step 3: Rearranging the even pages (the back/verso pages)

In step 3a we are selecting even pages, rotating them (-90 degrees for long-edge printing, 90 degrees for short-edge printing, if needed) and reflecting them for the first time. This is the mal-pdf-part3a.tex file and a preview of the first eight pages of 32:

% run: pdflatex or lualatex mal-pdf-part3a.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part1.pdf}
\pdfximage{\malfile}
\newcount\malc \malc=0
\loop
\advance\malc by 1%
\ifnum\malc<\pdflastximagepages
  \ifodd\malc
  \includepdf[fitpaper,pages={\the\malc},angle=-90,reflect]{\malfile}
  % We would use angle=90 for short-edge duplex printing.
  % We use angle=-90 for long-edge duplex printing.
  \fi
\repeat
\end{document}

mwe, step 3a

And this is the mal-pdf-part3b.tex file:

% run: pdflatex or lualatex mal-pdf-part3b.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},nup=4x4,frame]{mal-pdf-part3a.pdf}
\end{document}

mwe, step 3b


Step 4: Putting PDF files together

Our last step is to put those two PDF files together. The final PDF file consists of 4 pages (2 A4 papers) in the end. As we can see we are reflecting the back pages one more time. It's happening after the rearranging step, therefore the rectangles will start fitting to each other after printing.

I enclose the last TeX source code and a preview of the final PDF file. This file is ready to be printed (long edge, duplex, A4 paper) and cut into 16 pieces per paper afterwards.

In production we must be careful that there is usually 5 milimeters space around the page where printer cannot print due to technical limitations (office laser and ink printers). We usually use the scale parameter (twice in this example) in this final step. I'm using scale=1 in this example, in production I usually use scale=0.92.

% run: pdflatex or lualatex mal-pdf-part4.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part2b.pdf}
\pdfximage{\malfile}
\newcount\malc % inicialization of page counter
\malc=0 % setting the counter
\loop
\advance\malc by 1%
\includepdf[fitpaper,pages={\the\malc},scale=1]{mal-pdf-part2b.pdf} % 0.92 in production
\includepdf[fitpaper,pages={\the\malc},reflect,scale=1]{mal-pdf-part3b.pdf} % 0.92 in production
\ifnum\malc<\pdflastximagepages\repeat
\end{document}

mwe, step 4

Closing notes

In this example, we are running:

pdflatex mal-pdf-part1.tex  
pdflatex mal-pdf-part1.tex  
pdflatex mal-pdf-part2a.tex  
pdflatex mal-pdf-part2b.tex  
pdflatex mal-pdf-part3a.tex  
pdflatex mal-pdf-part3b.tex  
pdflatex mal-pdf-part4.tex  

We can easily change the nup parameter from 4x4 to anything we like, however, a change would be required in mal-pdf-part2b.tex and also in mal-pdf-part3b.tex.

We don't use frame parameter (the same two files) in production.

If we need to enter an empty page somewhere in the middle of the document, we usually use \newpage\mbox{} in the first step (twice as we typeset front and back pages).

If we enter less papers (<32 in this example) in mal-pdf-part1.tex then the remaining space will be empty. Due to the double reflecting method the empty space will also fit. I enclose an example where I entered 30 pages instead of 32.

mwe with some empty pages in it

1

The numbering doesn't match as I would think you want, but nevertheless this should accomplish what you want:

I use a \foreach loop that interates over the pages assumed to have 4 cards each. There are no precautions provided in case there aren't enough cards.

\documentclass[landscape]{scrartcl}
\usepackage{pdfpages}
\usepackage{pgffor}

\newcommand\setmycard[2]{%
  \edef\myimportedpagenumber{\number\numexpr(#1-1)*8+#2\relax}%%
  \expandafter\edef\csname ae@card@\number\numexpr#2\relax\endcsname{\myimportedpagenumber}}
\newcommand\getmycard[1]{\csname ae@card@\number\numexpr#1\relax\endcsname}

\begin{document}

\foreach \mycard in {1,2,3}
  {%%
    \setmycard\mycard{1}%%
    \setmycard\mycard{2}%%
    \setmycard\mycard{3}%%
    \setmycard\mycard{4}%%
    \setmycard\mycard{5}%%
    \setmycard\mycard{6}%%
    \setmycard\mycard{7}%%
    \setmycard\mycard{8}%%
    \includepdf[frame,pages={\getmycard{1},
                             \getmycard{3},
                             \getmycard{5},
                             \getmycard{7}},nup=2x2] {cards.pdf}%%
    \includepdf[frame,pages={\getmycard{6},
                             \getmycard{8},
                             \getmycard{2},
                             \getmycard{4}},nup=2x2] {cards.pdf}%%
  }

\end{document}
  • Thanks, that's a good start, I understand the vision behind it. Now I just have to determine the number of pages on the first place and then replace non-existant pages of the last quad with {}. – Christoph Jüngling Apr 11 '14 at 15:02

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.