R: put the table from "htmlTable" in the middle of the page (html report)

Viewed 90

I'm struggling to find a way to place my table in the middle of the page in my R markdown using "getDescriptionStatsBy" and "htmlTable" functions

library(Gmisc);library(htmlTable)

tables%>% 
    Gmisc::getDescriptionStatsBy(Age,sexe,by=Group,
                          statistics = list(continuous = getPvalAnova, 
                                          factor = getPvalChiSq, 
                                          proportion = getPvalFisher),
                           factor_fn = describeFactors,header_count = "n=%s",show_all_values=T,html = T)%>% 
   htmlTable::addHtmlTableStyle(align='c')%>% 
   htmlTable::htmlTable(caption  = "Demographic Table")

html report preview: enter image description here

I tried with the argument "align='c'" in addHtmlTableStyle function, but it doesn't work, the table is still in left side of the htlm report.. Any ideas ?! thanks

***** ANSWER *****

I found a solution : I just needed to add before the chunk <div align="center"> and </div> after

<div align="center">
```{r, echo = FALSE, fig.align = 'center', fig.width = 6, fig.height = 4, message = FALSE, warning = FALSE}

tables%>%
    Gmisc::getDescriptionStatsBy(Age,sexe,by=Group,
                          statistics = list(continuous = getPvalAnova,
                                          factor = getPvalChiSq,
                                          proportion = getPvalFisher),
                           factor_fn = describeFactors,header_count = "n=%s",show_all_values=T,html = T)%>%
    htmlTable::addHtmlTableStyle(align='c')%>%
    htmlTable::htmlTable(caption  = "Demographic Table")
```
</div>
0 Answers
Related