我正在运行一个自动生成报告的进程。它已经发挥到了一定程度。但现在,当我将 LaTeX 代码cat
放入文档中时,knitr::opts_chunk$set(result='asis')
不起作用。当我 knit
文档时,它会将 \
替换为 \textbackslash{}
。即使您单独运行 cat
命令,它也会生成正确的 LaTeX
代码:
---
title: "Untitled"
date: "October 15, 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, comment = NA, background = NA, results='asis')
```
```{r}
cat("
\\begin{tabular*}{1\\textwidth}{c c}
\\parbox[c]{0.4\\linewidth}{
{\\HUGE{\\textcolor{blue}{\\textbf{\\uppercase{Headline}}} }}\\\\
\\Large{{\\textsc{Example}}}\\\\
}&
\\parbox{0.25\\textwidth}{
\\icontext{MapMarker}{12}{Global}\\\\
\\icontext{MobilePhone}{12}{999 666 23}\\\\
\\icontext{Send}{12}{<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72011d1f17171f131b1e32151f131b1e5c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>}\\\\
}
\\end{tabular*}")
```
产生的错误:
我尝试过使用 knitr::asis_output()
,但它会导致相同的错误
正在生成的 Tex
如下:
\begin{document}
\maketitle
\textbackslash{}begin\{tabular\emph{\}\{1\textwidth\}\{c c\}
\parbox[c]{0.4\linewidth}{
{\HUGE{\textcolor{blue}{\textbf{\uppercase{Headline}}} }}\\
\Large{{\textsc{Example}}}\\
}\& \parbox{0.25\textwidth}{
\icontext{MapMarker}{12}{Glogab}\\
\icontext{MobilePhone}{12}{999 666 23}\\
\icontext{Send}{12}{<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5968a88808088848c89a58288848c89cb868a88" rel="noreferrer noopener nofollow">[email protected]</a>}\\
} \textbackslash{}end\{tabular}\}
\end{document}
最佳答案
这些问题终于有了解决方案:
knitr::raw_latex("here all your tex content")
instead of cat() + results='asis'.
关于r - 当 R 生成 LaTeX 代码时 Knit 'asis' 选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46760321/