2017-09-01 65 views
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} 

回答

0

您可以簡單地把

\DeclareGraphicsExtensions{.png,.pdf} 

您的文檔中,當你想PNG有優先權,然後

\DeclareGraphicsExtensions{.pdf,.png} 

以後如果你想回到PDF首選項。這在LaTeX文檔的正文中起作用,而不僅僅是在標題中。

相關問題