我正在运行一个自动生成报告的流程。它已经工作到一定程度。但是当knitr::opts_chunk$set(result='asis')
LaTeX代码进入文档时,cat
现在不起作用。当我\
文档时,它会将\textbackslash{}
替换为knit
。即使您自己运行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}{someemail@gmail.com}\\\\
}
\\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}{someemail@gmail.com}\\
} \textbackslash{}end\{tabular}\}
\end{document}
答案 0 :(得分:1)
终于有了解决这些问题的方法:
knitr::raw_latex("here all your tex content")
instead of cat() + results='asis'.