Latex math expression in RMarkdown table column name

I want to display a table in my markdown document and set the column names as latex mathematical formulas such as $ \ dot (m) _1 $.

I tried this:

knitr::kable(my.df[, c("Time", "MassFlowRate")],
             row.names = FALSE,
             col.names = c("Time", "$\dot{m}_1$"))

But that will not work.

In the end, I am not creating a PDF, but a Word document. Therefore, direct coding of the Latex table is not an option.

+5
source share
2 answers

You need to output \to R-code, so it \dotsshould be \\dots:

```{r}
my.df <- data.frame(Time=rnorm(10), MassFlowRate = rnorm(10))
knitr::kable(my.df[, c("Time", "MassFlowRate")],
             row.names = FALSE,
             col.names = c("Time", "$\\dot{m}_1$"))
```
+6
source

To get the current answer, you need to add , escape = FALSEto kable().

, tibble data.frame. , LaTeX . col.names.

'''{r}
library(tibble)
my_df <- tibble(Time=rnorm(10), '$\\dot{m}_1$' = rnorm(10))
knitr::kable(my_df, escape = FALSE)
'''
0

Source: https://habr.com/ru/post/1670304/


All Articles