title: Replace column names in kable/R markdown
body: <p>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, repeated names, etc.</p>
  
  <p>Is there an easy way of replacing the names in knitr to allow such formatting?</p>
  
  <h2>Proposed solution</h2>
  
  <p>What I have tried to do is suppress the printing of the data frame names and use <code>add_header_above</code> for better names and names that span several columns. Some advice I've seen says to use:</p>
  
  <pre><code>x &lt;- kable(df)
  gsub("&lt;thead&gt;.*&lt;/thead&gt;", "", x) 
  </code></pre>
  
  <p>to remove the column names. That's fine, but the issue is that when I subsequently <code>add_header_above</code>, the original column names come back. If I use <code>col.names=rep('',times=ncol(d.df))</code> in <code>kable(...)</code> the names are gone but the row remains, leaving a gap between my new column names and the table body. Here's a code chunk to illustrate:</p>
  
  <pre><code>```{r functions,echo=T}
  drawTable &lt;- function(d.df,caption='Given',hdr.above){
  require(knitr)
  require(kableExtra)
  require(dplyr)
  
  hdr.2 &lt;- rep(c('Value','Rank'),times=ncol(d.df)/2)
  x &lt;- knitr::kable(d.df,format='latex',align='c',
    col.names=rep('',times=ncol(d.df))) %&gt;%     
  kable_styling(bootstrap_options=c('striped','hover',
    'condensed','responsive'),position='center',
     font_size = 9,full_width=F)
  
  x %&gt;% add_header_above(hdr.2) %&gt;%
    add_header_above(hdr.above)
  }
  ```
  
  ```{r}
  df &lt;- data.frame(A=c(1,2),B=c(4,2),C=c(3,4),D=c(8,7))
  hdr.above &lt;- c('A2','B2','C2','D2')
  drawTable(df,hdr.above = hdr.above)
  ```
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lAtWE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lAtWE.png" alt="enter image description here"></a></p>