【问题标题】:R chunk code stay inside the Beamer frameR 块代码留在 Beamer 框架内
【发布时间】:2012-11-05 20:27:24
【问题描述】:

这是我的 MWE 代码。

\documentclass{beamer}
\begin{document}

<<setup, include=FALSE>>=
# smaller font size for chunks
opts_chunk$set(size = 'footnotesize')
options(width=60)
@


\begin{frame}[fragile]
\frametitle{Test1}

<<boring-random>>=
y <- c(5, 7, 15, 17, 17, 19)
Trt <- gl(n = 3, k = 2, length = 3 * 2, labels = paste("Trt",
1:3, sep = ""), ordered = FALSE)
Data <- data.frame(Trt, y)
Fit1 <- aov(formula = y ~ Trt, data = Data, contrasts = list(Trt = "contr.sum"))
ANOVA1 <- anova(Fit1)
Coeffs1 <- coefficients(Fit1)
@
\end{frame}

\end{document}

我正在努力将 R 块代码保留在 Beamer 框架内。我想知道管理 R 块代码以使它们留在 Beamer 框架内的有效方法是什么。谢谢

【问题讨论】:

  • 可以选择使用 formatR 包中的 tidy.source 之类的东西吗?
  • knitr默认使用tidy.source,宽度由getOption('width')决定

标签: r knitr beamer


【解决方案1】:

最好的办法是通过tidy=FALSE关闭tidy选项,然后手动换行。

<<boring-random, tidy=FALSE>>=
y <- c(5, 7, 15, 17, 17, 19)
Trt <- gl(n = 3, k = 2, length = 3 * 2, labels = paste("Trt",
  1:3, sep = ""), ordered = FALSE)
Data <- data.frame(Trt, y)
Fit1 <- aov(formula = y ~ Trt, data = Data,
  contrasts = list(Trt = "contr.sum"))
ANOVA1 <- anova(Fit1)
Coeffs1 <- coefficients(Fit1)
@

这将始终有效。另一种方法是在options()knitr FAQ 8)中设置更小的width,你可能需要尝试几次才能获得理想的width。在你的情况下,60 显然太大了。

【讨论】:

  • 它还可以帮助稍微减小文本边距,例如将\setbeamersize{text margin left = 16pt, text margin right = 16pt} 放在序言中,如in this answer
猜你喜欢
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多