Добавьте col.names () к функции kable () в начале и удалите подчеркивание = TRUE из функции row_spe c ().
kable(ranknew, format = "latex", row.names = FALSE,
col.names = c("Provinces","Brokerage Name","Written Pren....","Loss Ratio","New Business( Whatever comes here)"),
align = c("c", "l", "r", "r", "r"),
caption = paste("We had", nrow(ranknew) ,
"brokerages give us 100+ new policies in", year(Sys.Date())-1),
longtable = TRUE, booktabs = TRUE) %>%
kable_styling(latex_options = c("HOLD_position", "repeat_header"), full_width = F, font_size = 9, position = "center") %>%
column_spec(column = 1, width = "3cm")%>%
column_spec(column = 2, width = "8cm") %>%
column_spec(column = 3, width = "2cm") %>%
column_spec(column = 4, width = "1.5cm") %>%
column_spec(column = 5, width = "1.5cm") %>%
row_spec(row = 0, bold = TRUE, background = "orange",
color = "black", italic = FALSE, monospace = FALSE, strikeout = FALSE) %>%
print(floating = FALSEFALSE, row.names = FALSE)
Этот пример работает на моем конце с набор данных iris.
library(knitr)
library(kableExtra)
library(tidyverse)
kable(iris, format = "latex", row.names = FALSE,
col.names = c("Provinces","Brokerage Name","Written Pren....","Loss Ratio","New Business( Whatever comes here)"),
longtable = TRUE, booktabs = TRUE) %>%
kable_styling(latex_options = c("HOLD_position", "repeat_header"), full_width = F, font_size = 9, position = "center") %>%
column_spec(column = 1, width = "3cm")%>%
column_spec(column = 2, width = "8cm") %>%
column_spec(column = 3, width = "2cm") %>%
column_spec(column = 4, width = "1.5cm") %>%
column_spec(column = 5, width = "1.5cm") %>%
row_spec(row = 0, bold = TRUE, underline = TRUE, background = "orange",
color = "black", italic = FALSE, monospace = FALSE, strikeout = FALSE) %>%
print(floating = FALSEFALSE, row.names = FALSE)