PCRL
PCRL

Reputation: 109

How to center title/caption in Kable function in R

Does anyone know how i can center the caption in the kable function?

This is my code:

Exhibit1 <- setDT(A)

colnames(A) = c(" ", "Nº Y", "Nº X")

Exhibit1 %>%
  kbl(caption = "Database by Country") %>%
  kable_classic(full_width = F, position = "center", html_font = "Times New Roman")

I can adjust the position of the table columns themselves (center, left, etc), however, the title/caption of this table is always aligned to the left.

Any ideas, please?

PS. If anyone knows a better table generating function, you are welcome to share it with me... I just need a good design.

Thank you

Upvotes: 0

Views: 769

Answers (1)

manro
manro

Reputation: 3677

Let's try the gt library

library(gt)

dt <- mtcars[1:5, 1:6]

testTable <- gt(dt)

testTable <-
     testTable %>%
     tab_header(title = md("**Title in the center of the table**")) %>%
     tab_options(heading.title.font.size =  px(18))

enter image description here

Upvotes: 0

Related Questions