My data frame has ugly column names, but when displaying the table in my report, I want to their \"real\" names including special characters \'(\', new lines, greek letters, rep
I am not sure where you got the advice to replace rownames, but it seems excessively complex. It is much easier just to use the built-in col.names
argument within kable
. This solution works for both HTML and LaTeX outputs:
---
output:
pdf_document: default
html_document: default
---
```{r functions,echo=T}
require(knitr)
df <- data.frame(A=c(1,2),B=c(4,2),C=c(3,4),D=c(8,7))
knitr::kable(df,
col.names = c("Space in name",
"(Special Characters)",
"$\\delta{m}_1$",
"Space in name"))
```
PDF output:
HTML output: