Double headers on DT tables do not match. html_document

I got a problem with headers on my table on html_document. I use container to create double headers (found on random forum):

sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
       th(
            th(colspan = 2, "2018"),
            th(colspan = 2, "2019"),
            th(colspan = 2, "2020")
       ),
    tr(
      lapply(rep(c('DATE:', 'VALUE:'), 3), th)
    )
  )
))
)

DT::datatable(dfcompany1, width = '100%', container = sketch, options=list(scrollX=TRUE),rownames = FALSE)

And a result:

I want Years to be right between DATE and VALUE, unfortunatly the position is not correct. How can I correct this?

the sketch you posted above didn't create the table header as expected, see code example below for the updated version:

sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
        th(colspan = 2, "2018"),
        th(colspan = 2, "2019"),
        th(colspan = 2, "2020")
      ),
      tr(
        lapply(rep(c('DATE:', 'VALUE:'), 3), th)
      )
  ))
)

dfcompany1 <- mtcars[1:3, 1:6]

DT::datatable(dfcompany1, width = '100%', container = sketch, rownames = FALSE)

Thank you very much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.