在latex beamer中,您可以编写以下代码来获取覆盖动画:
\begin{overprint}
\foreach \x in {1,2,3}{%
\only<\x>{%
\includegraphics{figure/plot-\x.pdf}
}
}
\end{overprint}如何让knitr生成这样的输出并使用覆盖动画?
PS:我知道fig.out='animate',但它只适用于Acrobat,而我想要一个通用的解决方案。
发布于 2020-02-23 17:53:04
我能够编写一个chunk_hook来扫描块输出,并在每个图周围添加叠印环境和\only<i>部分:
这里是钩子:
library(stringi)
overlay_hook = function(x, options) {
x = knitr:::.chunk.hook.tex(x, options)
if (!is.null(options$overlay_start)) {
ind_matches = stri_locate_all_regex(x, "\\\\includegraphics")[[1]]
stri_sub_all(x, from = ind_matches[,2]+1, length = 0) =
paste0("<", seq_len(nrow(ind_matches)) + options$overlay_start - 1 ,">")
}
return(x)
}
knitr::knit_hooks$set(chunk = overlay_hook)要使用它,你必须将overlay_start设置为一个值(例如,如果它应该从第一个动画步骤开始,则设置为1)
<<plot, results='hide', overlay_start = 1, fig.height=3>>=
for (i in 1:3)
plot(function(x) x^i)
@https://stackoverflow.com/questions/60360998
复制相似问题