I want to display a table in my markdown document and set the column names to be 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 it doesn't work.
I don't generate a PDF, but a Word document in the end. So directly coding a Latex table is not an option.
You need to escape \
passed into R code so \dots
should 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$"))
```
To get the current answer to work, you need to add , escape = FALSE
in kable()
.
Also, I prefer using a tibble
to a data.frame
. That way I can specify the LaTeX code in the column names directly. No need to use col.names
.
```{r}
library(tibble)
my_df <- tibble(Time=rnorm(10), `$\\dot{m}_1$` = rnorm(10))
knitr::kable(my_df, escape = FALSE)
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With