Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

center DT datatable in R markdown report

Tags:

r

r-markdown

dt

I have a very small table and I'm using DT throughout my project so I want this small table to look constant.

When using the the width argument in DT::datatable() to reduce its width, the table is left justified while centering it would look much nicer.

I've tried using fig.align = 'center' in the chunk options but it hasn't helped.

library(DT)
datatable(cars, width = 300)
like image 932
James Avatar asked Sep 16 '25 04:09

James


1 Answers

How about using <div> if you use HTML report:

<div align="center">
```{r}
library(DT)
datatable(cars, width = 300)
```
</div>
like image 105
Jane Avatar answered Sep 17 '25 18:09

Jane