为了演示如何使用
pdfpages package插入pdf页面,我首先使用
pdf()
命令创建一个包含四个页面的pdf文件。
.Rnw(Knitr)脚本如下:
\documentclass[a4paper]{article}
\usepackage[final]{pdfpages}
\usepackage[pagestyles]{titlesec}
\usepackage{hyperref}
\title{An example on how to add external pdf pages}
\begin{document}
\maketitle
\tableofcontents
\section{First section}
\subsection{First subsection}
This is an empty section with a chunk to create one pdf with four pages
<<mtcarsplot, echo = TRUE, eval = TRUE, fig.show='hide'>>=
library(knitr)
pdf(file="figure/mtcarsplot.pdf",onefile=TRUE)
ggplot(mpg, aes(drv, model)) +
geom_point() +
facet_grid(manufacturer ~ ., scales = "free", space = "free") +
theme(strip.text.y = element_text(angle = 0))
ggplot(mtcars, aes(wt, mpg))+ geom_point(aes(colour=factor(cyl), size = qsec))
ggplot(mpg, aes(x=factor(cyl), y=hwy, fill=factor(cyl)))+ geom_violin(scale = "width")
mosaicplot(Titanic, color = TRUE)
dev.off()
@
\phantomsection
\addcontentsline{toc}{subsection}{Second subsection (phantom)}
\includepdf[pages={1-2,{},4},nup=2x2]{figure/mtcarsplot.pdf}
\end{document}
要插入外部文档的页面,请使用以下 HTML 代码:
。
\includepdf[<key=val>]{<filename>}
最简单的方法是使用
\includepdf[pages=-]
,它将包含文档中的所有页面。
包含页面的代码为:
\includepdf[pages={1-2,{},4}],nup=2x2]{figure/mtcarsplot.pdf}
{1-2,{},4}的意思是我包括了第1到2页,空白页,然后是第4页。
另一个命令是nup=2x2,在同一页中以两行两列的方式包含了四个页面。
通常将外部pdf包含为所创建文档的章节或子章节非常有用,这可以通过以下方式完成:
\phantomsection
\addcontentsline{toc}{subsection}{Second subsection (phantom)}
输出显示四个页面在一页中,其中一个页面为空白,并带有包含虚拟章节的目录。
![pdfpage_example](https://istack.dev59.com/QK6QA.webp)
pandoc -o stuff.tex stuff.rmd
),并在LaTeX文档中使用\include{}
命令引入它? - Ben Bolker