I use a very similar workflow for you, and it is best to drop the often clumsy xtable package and use the pander package to print your tables. You can wrap any object that can be displayed as a table in the general pander() function. This is a wrapper for the pandoc.table() function, which has several options. If you specify the style = "XXX" option, you can achieve what you are asking for here. There are 4 different styles from which you can choose; multiline (default), grid, simple, or rmarkdown. I often insert rmarkdown documents from Rstudio and then convert them to Word documents using the pander package:
library(pander) Pandoc.convert("C:/Users/BlahBlahBlah/Document.md", format="docx")
All 4 styles of the table turn into table objects when converted to the .docx format, but only one table style looks right in the .docx document and the .html file that arises from the initial "knitting". This style is "rmarkdown". You can implement this in two ways. One could:
```{r table, results='asis'} pandoc.table(myTable, style = "rmarkdown") ```
I prefer to set the table style globally at the beginning of my document, however, so that all my tables have the same formatting, and also allow me to use a more concise pander(x) instead of the more detailed pandoc.table(x, style = "someStyle") :
```{r table, results='asis'} panderOptions("table.style", "rmarkdown") pander(myTable) ```
However, there are some side effects of using the rmarkdown style. Basically, it does not support newlines in cells, so the buyer is wary. I experimented with different styles and ultimately decided that I like the default “multiline” style because of its flexibility with line breaks in cells, although the .html files I generate look silly. This does not bother me, since I really only use .docx files, which I convert from .md files. I wrote a post about creating beautiful tables that you might find useful. It weighs the pros and cons of several methods, including xtable() and several pander() scripts.
rnorberg
source share