2017-09-01 9 views
1

knitrを使って(ラテックス)文書を作成するときに、pdfとpngの両方の画像ファイルを生成したいのですが。これはdev = c( "pdf"、 "png")を使って行うことができます。 しかし、私はラテックスの図形環境で2つのうちどちらが選択されたかを(図ごとに)選択することができないようです。現在、図1のpng入力ファイルと図2のpdf入力ファイルを得ることができる唯一の方法は、dev = "png"、fig.ext = " png ")。knitrでpngまたはpdfのどちらかを選択してください。

私はまだ両方を生成できる方法がありますが、ラテックスレベルでどちらが表示されるかを選択できますか? \ includegraphicsコマンドの拡張を許可することで、簡単に解決できます。

任意の入力は感謝...

ロン

最小例:あなたは単にあなたがPNGが優先したいとき、ドキュメント内の

\DeclareGraphicsExtensions{.png,.pdf} 

を置くことができます

\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{.pdf,.png} 

後でPDFの設定に戻る場合。これはヘッダーだけでなく、LaTeXドキュメントの本体でも機能します。

関連する問題