我正在尝试在RMD文件中呈现以下表格:
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|}
\hline
\\ \hline
\end{tabular}
\end{table}
迄今为止还没有成功。除了公式以外,rmarkdown不能将LaTeX环境编译成HTML的根本原因是什么?请注意,保留HTML标记。
我正在尝试在RMD文件中呈现以下表格:
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|}
\hline
\\ \hline
\end{tabular}
\end{table}
迄今为止还没有成功。除了公式以外,rmarkdown不能将LaTeX环境编译成HTML的根本原因是什么?请注意,保留HTML标记。
pandoc
自动识别任意混合的标记语言。LaTeX数学标记只能在Markdown文档中使用,因为有一个rmarkdown扩展来处理它。tex2markdown
背后的思想在这里解释了。---
output: html_document
---
# My document
This is `rmarkdown`.
This table is converted from LaTeX:
```{r, results = "asis", echo = FALSE, message = FALSE}
library(knitr)
tex2markdown <- function(texstring) {
writeLines(text = texstring,
con = myfile <- tempfile(fileext = ".tex"))
texfile <- pandoc(input = myfile, format = "html")
cat(readLines(texfile), sep = "\n")
unlink(c(myfile, texfile))
}
textable <- "
\\begin{table}[]
\\centering
\\caption{Food order}
\\begin{tabular}{| l | l |}
\\hline
Hamburgers & 3 \\\\
Hot dogs & 2 \\\\ \\hline
\\end{tabular}
\\end{table}
"
tex2markdown(textable)
```
---
Time for *lunch*.
并非所有的LaTeX功能都能转换为HTML,但对于简单的任务,这应该能起作用。请注意,反斜杠需要通过另一个反斜杠进行转义。
这主要是概念验证。在生产中,请在RNW文档中使用LaTeX表格,在RMD文档中使用markdown表格!