Skip to content

Instantly share code, notes, and snippets.

@yihui
Created May 27, 2012 16:27
Show Gist options
  • Save yihui/2814968 to your computer and use it in GitHub Desktop.
Save yihui/2814968 to your computer and use it in GitHub Desktop.
Custom graphics devices in knitr
\documentclass{article}
\begin{document}
This demo shows you how to use the Palatino font in the Cairo PDF device.
<<setup>>=
my_cairo = function(file, width, height) {
cairo_pdf(file, width, height, family = 'Palatino')
}
@
Now we can use the custom device; remember to specify the figure extension to be
\texttt{pdf}.
<<test-cairo, dev='my_cairo', fig.ext='pdf', fig.width=4.5, fig.height=3>>=
plot(1, main='Hello, Palatino', xlab='This is x-axis', ylab='This is y-axis')
@
But since knitr 0.6, this can be much easier:
<<dev-args, dev='cairo_pdf', dev.args=list(family='Palatino'), fig.width=4.5, fig.height=3>>=
plot(1, main='Hello, Palatino', xlab='This is x-axis', ylab='This is y-axis')
@
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment