Graphics, Figures & TablesPDF Pages Alternating

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
youngprof
Posts: 8
Joined: Thu Apr 08, 2010 9:18 pm

PDF Pages Alternating

Post by youngprof »

Hello all,

I'm looking to do something a little tricky using the pdfpages package. I have two pdfs and I'm trying to combine them alternately (e.g, make a new pdf using p1-doc1, p1-doc2, p2-doc1,p2-doc2, p3-doc1,p3-doc2,etc.). Is there a trick for this, or perhaps a different package?

Thanks,

YP

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

PDF Pages Alternating

Post by frabjous »

The package does have a \includepdfmerge command, but it doesn't look like it would do quite what you want in any easy way, anyway.

You could, however, make use of whiledo from if the ifthen package to loop through all the page numbers, e.g.:

Code: Select all

\documentclass{article}
\usepackage{ifthen}
\usepackage{pdfpages}
\begin{document}
\newcounter{incpages}%
\setcounter{incpages}{0}%
\whiledo{\theincpages < 9}%
{%
     \stepcounter{incpages}%
     \includepdf[pages=\theincpages]{doc1.pdf}%
     \includepdf[pages=\theincpages]{doc2.pdf}%
}
\end{document}
But there are two less than perfect things about this: (1) I put in the number "9" because the documents I was testing with had nine pages each; You can change this to whatever but it's going to be pretty complicated if you don't know how many pages there are beforehand. (2) It's not going to work if doc1 and doc2 have a different number of pages (although in that case, it isn't obvious what the "right" thing do would be anyway).

While some creativity, you could probably figure out a way past these problems, however, but it would mean knowing a bit more about what you know about these documents and when you know them.

There are of course other tools you could use to do this too besides the package. I could find some if you're interested.
Post Reply