Replace column names in kable/R markdown

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: enter image description here

HTML output: enter image description here