【问题标题】:Knitr escape latex special characters (e.g., ~, $) in R codeR 代码中的 Knitr 转义乳胶特殊字符(例如 ~、$)
【发布时间】:2014-11-06 04:50:31
【问题描述】:

当我在此 knitr 文档的输出上运行 LaTeX 时,它会崩溃,因为 LaTeX 特殊字符没有正确转义。任何提示如何解决这个问题?

\documentclass{beamer} 
\begin{document}
\begin{frame}{Unescaped dollar signs and tildes}

In this example, neither the tilde nor the dollar sign
will appear in the pdf document, and the dollar sign
will cause a \LaTeX error.

<<xtable, results="asis">>=
n <- 100

x <- rnorm(n)

y <- 2*x + rnorm(n)

out <- lm(y ~ x)

library(xtable)

xtable(summary(out)$coef, digits=c(0, 2, 2, 1, 2))
@

\end{frame}
\end{document}

【问题讨论】:

    标签: r latex knitr beamer


    【解决方案1】:

    如果您的框架包含带有特殊乳胶字符的 knitr 块,您需要添加 [fragile] 选项:

    \begin{frame}[fragile]
    

    来源:knitr webpage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多