The package pdfpages
let’s you include a complete PDF or any combination of pages into a LaTeX document.
First load the package in the preamble.
\usepackage{pdfpages}
Now use any of the possible options below to include pages from a PDF.
Include the first page
\includepdf{file}
The whole document
\includepdf[pages=-]{file}
A forward or backward range
\includepdf[pages=2-8]{file} \includepdf[pages=8-2]{file} \includepdf[pages=last-1]{file}
You never know when that may come in handy. However, the keyword last
actually can be quite useful in case the number of pages in the document may change.
Several single pages with/without blanks
\includepdf[pages={3, 6, 1}]{file} \includepdf[pages={3, {}, 9}]{file}
Copies of the same page
\includepdf[pages={5, 5, 5}]{file}
And finally, a bit of everything
\includepdf[pages={3-6, {}, 1, 7}]{file}
The package also provides the option nup=axb
to print several logical pages on a single physical page (the parameter a
being the number of columns and b
the number of rows). LaTeX scales the logical pages to fit within the margin of the physical page. In the example below the first 4 logical pages will be placed on the first physical page and the rest on the next.
\includepdf[nup=2x2, pages=1-7]{file}
ofer
This is great! Do you know how to embed pdf pages also in html?
John Baker
Just a quick note to let you know I enjoy your LaTeX tidbits. I’ve learned a few useful techniques following your blog. Thanks.
tom
Thanks, appreciate it. Tom.
Ben
Do you know if this will allow you to insert a page into a Beamer presentation?
One of the things I’d like to be able to do is show graphs that fill the full page (no headers, slide design, etc.) of a slide. I’ve had the thought that since I already export graphs to pdf and import them that way, it’d be great if I could just show the graph pdf instead of showing it in a frame.
tom
That’s funny, I was just trying to do that and yes it works :-):
Found it on stackexchange. Best, Tom.
Allan
Hi Tom,
I am preparing my manuscript for publication and my co-authors want me to remove the trailing dots and page number in the Figure legend. I tried using \renewcommand{\cftdotsep}{\cftnodots}. This does remove the dots but I get an error message saying that cftnodots is undefined. I still haven’t found a way to remove page numbers that trail after each caption.
Also, in the figure legend each caption is labelled 1, and so forth, my co-authors want it to read Fig. 1 etc., according to the style of the journal we are submitting to. Do you have any advice as to how I clear up these details?
I found tonnes of other stuff on your site and really appreciate your efforts. Thanks a lot.
Allan
tom
Hi Allan,
I wasn’t able to reproduce the error you get with
cftnodots
, unless I don’t load thetocloft
package.You’ll find an answer to your question on how to remove the page number in the list-of-figures / list-of-tables here.
This comment will help you adding the word
Fig.
in front of the figure number.Best, Tom.
Allan
Hi Tom,
Thanks for your comments. I already have loaded the tocloft package, and the only thing that comes to my mind is that it may be interfering with the subfig package. One of the errors I get is that loft depth is already defined and it points towards the subfigure package that I use.
Thanks
Allan
Allan
Sorry about my rant here Tom. I figured out how to change lof into Fig., but when I use your advice about getting rid of page numbers (from a previous advice), it completely screws up my lof. I don’t have a loc, would that be why?
Almost ready to use OpenOffice…
Allan
tom
Hi Allan,
Sorry for not getting back to you sooner. There is a known conflict between the
subfig
and thetocloft
packages. Try loading thetocloft
package with thesubfigure
option:Or the more flexible solution from here.
Concerning your list of figures issue, I doubt it’s because you don’t have a table of contents. They are independent, with their respective content saved in two different meta-files (*.lof and *.toc).
I briefly tried the piece of code that I linked to in my previous comment and it works smoothly. But it’s only a minimal example and your document might have lots of other stuff that may interfere so…
Do you get any errors when typesetting?
Best, Tom.
Allan
Hi Tom,
I finally figured out how to get my tables into the main text so that endfloat isn’t affecting them. I used tabular and now my tables are where they should be, but table captions are not following the tables (I don’t want captions in list of tables as I do for the figures).
I used this code to get FIGURE CAPTIONS in list of figures in my class file:
Is this preventing me from having TABLE captions appear below tables in the main text?
I used the package \capt-off to get captions in TABLES inside the tabular environment such that my tabular looks like this:
But, I still don’t get the captions below each their table. Do you have any idea of what’s going on? It’s the last thing I need to have fixed before I can submit.
Allan
tom
Hi Allan,
When I use the code pieces above, the caption appears below the table. Have you tried surrounding the whole thing with a
table
floating environment? If that doesn’t help, please provide a full minimal example that I can paste into a document and typeset.Thanks, Tom
tom
By the way, you’ll need to surround any code that has “@” within your tex-document by
\makeatletter...\makeatother
. Tom.Allan
Hi Tom,
I finally solved the problem. Because I use endfloat latex put both figure and table captions in listoffigures and listoftables (and figures and tables on subsequent pages). To avoid tables being affected by endfloat I avoided the table environment and sufficed with tabular. Using this approach tables remained in text, but not the captions. So here’s what I did in my class file to solve that:
Now it all works
Allan
tom
Great! Thanks for posting the solution. Tom.
QJL
An useful latex trick!
vishal
I am trying this code but it does not work with pdflatex
Please help me include pdf
tom
Hi Vishal,
If your PDF covers the whole page, you should remove the
figure
environment. In case your PDF contains a figure that you’d like to add to your document, use thegraphicx
package instead.vishal
I tried your code does not work pdflatex. When I eliminate the figure section it does and generate dvi and the pdf it gives me blank page as output.
Thank you
tom
If
\includepdf
is wrapped in a\begin{figure} ... \end{figure}
, the output is blank on my system. Once I removed that, it worked. Not sure what the problem is if that didn’t help. The log file my give you some clue…Cheers, Tom
Prangsai Tiangtrong
This is very helpful. Thank you so much.
Esben Poulsen
Dear Tom,
Thanks for the epic trick! It works like a charm.
One tiny (but probably tricky request): Is it possible to have the header/footer/page numbers of the main tex file overlay the inserted full page pdf?
I need this because I am including papers into my PhD-thesis, and I don’t want the reader to be confused by the papers page numbers :).
Thanks!
/Esben
Esben Poulsen
Got it!
is what I needed š
tom
Thanks for posting your solution. Best, Tom
Sven
Hi Tom,
are you aware of a way to keep the links within an included pdf working?
TIA
Sven
tom
Hi Sven,
Thanks for your comment. Use pax to keep links in PDFs. Check the readme/documentation for details on how it works.
HTH,
Tom
SARTORETTO FLAVIO
Using \includepdf, by pdflatex on Mac, I obtain one page with all pdf pages superimposed.
Any hint to fix this problem?
Thank you in advance
tom
Hi Flavio,
Thanks for your comment. You can find a possible solution here. If this doesn’t solve the problem, please provide a minimal working example. To help, I need to replicate the problem on my computer.
Best,
Thomas
SARTORETTO FLAVIO
Dear Thomas, thank you very much for your hint. I solved my problem.
Best!
jayantrao88
Hi Tom,
I have multiple 20) graphs saved as pdf which I am using to insert in one page, I am able to do it but I would also like to caption each graph and have a common caption for all the graphs together. How to achieve that?
TIA,
Jayant
tom
Hi Jayant,
You probably want to use one of the subfigure packages, such as
subfig
. See my post here on the package for more details.Cheers, Tom
Tihana
Hi Tom,
I would need to insert a pdf document of several pages in my thesis, so I was using
\includepdf[pages=-,scale=0.8,pagecommand={\pagestyle{fancy}}]{workflow}, but I would need to have this document in the list of figures (it can be also seen as a table, thus list of tables). How can I achieve this?
Cheers
Tihana
tom
Hi Tihana,
You can manually add entries using one of the two lines of code below.
lof
stands for list of figures. Alternatively, uselot
for list of tables. Insert this command just above yourincludepdf
to get the page number right.Let me know if you get stuck.
Best, Tom
Tihana
Hi Tom,
thank you very much for your prompt reply! I guess the manual addition goes in contrast with \listoffigures that I am using with [nottoc]{tocbibind}, since when I compile it screws up the list of figures and tables (they do not appear at all…). Not sure what is the problem, since I do not get any error, they simply disappear.
Best,
Tihana
tom
Hi Tihana,
Please provide a minimal working example, so I get an idea of what other packages/configuration you use.
Best,
Tom
Tihana Vujinovic
Hi Tom,
thanks for your prompt reply!
Here roughly the configuration, with example.
What I think might be causing the conflict is the hyperref. Maybe. But also I cannot get a number in the list and the correspondent page number. So that is screwing up the list of other figures.
Another thing is the positioning of the pdf I need to insert. If I put it after a couple of figures, that is where I would like it to appear, while what he does is putting it straigth before anything else. While I can manipulate this with the graphicx package, I don’t know how to fix the position of the pdf with pdfpages.
Many thanks!
Tihana
tom
Thanks for the example. I wasn’t aware of the
addtolist
option to\includepdf
before (see pdfpages package documentation). This option adds the entry to the list of figures/tables.Figure
is a floating environment, meaning that a figure float down your document until LaTeX finds enough space for it. However, you can force figures to be printed before some other content using\clearpage
. If you add\clearpage
just before\includepdf
, all figures should appear before the PDF.Cheers, Tom