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}

相關內容