在 knitr 中的新页面上创建块

在 knitr 中的新页面上创建块

我遇到这样一种情况,我正在 \enumerate 中编织一堆图形,而且图形很大,因此我希望每个图形都有一页。

\documentclass{article}

\begin{document}
\begin{enumerate}

\item Lets' try figure 1. 
<<fig1, include=TRUE, fig.pos='htbp', fig.align='center', fig.cap='fig1', fig.height=5, fig.width=5>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@

\item Lets' try figure 2. 
<<fig2, include=TRUE, fig.pos='htbp', fig.align='center', fig.cap='fig2'>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@

\item Lets' try figure 3. 
<<fig3, include=TRUE, fig.pos='htb!', fig.align='center', fig.cap='fig3'>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@
\end{enumerate}

\end{document}

我可以使用 fig.width 和 fig.height 来控制每个图形的大小,但我想是否有一种优雅的方式可以让每页显示一个图形?也许可以按枚举或分块进行更改?谢谢。

答案1

一种方法是手动使用 \newpage 命令。如果是

\documentclass{article}

\begin{document}
\begin{enumerate}

\item Lets' try figure 1. 
<<fig1, include=TRUE, fig.pos='htbp', fig.align='center', fig.cap='fig1', fig.height=5, fig.width=5>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@
\newpage
\item Lets' try figure 2. 
<<fig2, include=TRUE, fig.pos='htbp', fig.align='center', fig.cap='fig2'>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@
\newpage
\item Lets' try figure 3. 
<<fig3, include=TRUE, fig.pos='htb!', fig.align='center', fig.cap='fig3'>>=
set.seed(1213)  # for reproducibility
x = cumsum(rnorm(100))
mean(x)  # mean of x
plot(x, type = 'l')  # Brownian motion
@
\end{enumerate}

\end{document}

相关内容