-
-
Save yihui/1803930 to your computer and use it in GitHub Desktop.
% this is a simplified version of | |
% https://github.com/yihui/knitr/blob/master/inst/examples/knitr-beamer.Rnw | |
\documentclass{beamer} | |
\begin{document} | |
<<setup, include=FALSE>>= | |
# smaller font size for chunks | |
opts_chunk$set(size = 'footnotesize') | |
@ | |
\title{A Minimal Demo of knitr} | |
\author{Paul Hiemstra \and Yihui Xie} | |
\maketitle | |
% very important to use option [fragile] for frames containing code output! | |
\begin{frame}[fragile] | |
You can test if \textbf{knitr} works with this minimal demo. OK, let's | |
get started with some boring random numbers: | |
<<boring-random>>= | |
set.seed(1121) | |
(x=rnorm(20)) | |
mean(x);var(x) | |
@ | |
\end{frame} | |
\begin{frame}[fragile] | |
The first element of \texttt{x} is \Sexpr{x[1]}. Boring boxplots | |
and histograms recorded by the PDF device: | |
<<boring-plots, fig.width=5, fig.height=5, out.width='.45\\linewidth', fig.show='hold'>>= | |
## two plots side by side (option fig.show='hold') | |
boxplot(x) | |
hist(x,main='') | |
@ | |
\end{frame} | |
\end{document} |
Possible weird clue, the size option has an effect on hash and quote marks. For example in the comment line about two plots side by side, the hash signs and the quotes get bigger or smaller as I change:
size = 'huge'
size = 'tiny'
But the rest of the comment and all the R code stays the original size. Something to do with available fonts?
you need to install the development version; this will be a new feature in v0.6: https://github.com/yihui/knitr/blob/master/NEWS
Thanks for response and link to news of v0.6. Development version not easy to install under Windows, (no Rtools for R-2.15.0, spaces in paths problem, too much). Maybe come back when 0.6 is on CRAN.
I have pushed a version to R-Forge, so you should be able to install the Windows version once the build is ready there: https://r-forge.r-project.org/R/?group_id=656
Would you have a beamer example with references working properly for figures and tables?
The reference bit works, but the label does not print in the figure caption:
<<Figure1, fig.cap = 'My Figure'>>=
...etc.
plot(x, y)
@
\end{frame}
The above has a caption like: Figure: My Figure instead of Figure 1: My Figure
This \ref{fig:Figure1} prints as Figure 1, as expected.
And how to do the same with a table, e.g.
<<Table1, echo = FALSE, results = 'asis'>>=
library(xtable)
xtable(summary(lm(y~x))$coefficients, caption ="Summary")
@
Couldn't get it to work at all inside the beamer class.
Thanks!
font size option is not working for me. (The older trick with the footnote environment works). The script above gives me normalsize whatever size I ask for, (?highlight). Have tried many options. Want to shrink the size of R code in a frame.
Windows 7
MikTeX 2.9
R 2.15.0
tikzDevice_0.6.2
knitr_0.5