1
当我使用knitr创建(胶乳)文档时,我喜欢生成pdf和png图像文件。这可以使用dev = c(“pdf”,“png”)来完成。 但是,我似乎无法选择(以每个数字为单位)两个选项中的哪一个选择在我的乳胶图形环境中。目前,我可以获得图1的png输入文件和图2的pdf输入文件的唯一方法是仅生成所需的格式(通过使用dev =“png”,fig.ext =“ PNG“)。当两者都可用时,选择PNG或pdf格式的编码器
有没有一种方法可以同时生成两者,但是在乳胶层面上可以选择显示哪一个?我想可以通过在\ includegraphics命令中允许扩展来轻松解决这个问题。
任何输入赞赏...
罗恩
小例子:
\documentclass[a4paper,12pt]{article}
%\VignetteEngine{knitr::knitr}
\DeclareGraphicsExtensions{.pdf,.png}
\begin{document}
%\maketitle
<<knitrInitialization,echo=FALSE>>=
require("knitr", quietly=TRUE)
opts_chunk$set(comment=NA,background='transparent',size='small',fig.width=6,fig.height=6,out.width='\\textwidth',dev=c('pdf','png'))
@
%% this one generates two figures, and the pdf version is shown
%% because of the order in DeclareGraphicsExtensions
\begin{figure}[tb]
\centering
<<testPDF,echo=FALSE>>=
plot(1:10)
@
\caption{PDF figure}
\label{fig:pdf}
\end{figure}
%% if I want to show a png (e.g., because the pdf is too large) I can
%% only do that by not generating a pdf in the first place
\begin{figure}[tb]
\centering
<<testPNG,echo=FALSE,dev='png',fig.ext='png'>>=
plot(1:10)
@
\caption{PNG figure}
\label{fig:png}
\end{figure}
\end{document}