KableExtra: Modify Caption Size

Dear All,

I enclose a rather long example of a table I am creating.
My question is rather elementary but I cannot find an answer: how do I modify the caption font size?
Many thanks!


library(kableExtra)
library(dplyr)

 ## dt <- readRDS("test_table.RDS")


dt <- structure(list(Reporter = c("World", "Australia", "Brazil", "Canada", 
"China", "EU28", "Hong Kong", "India", "Japan", "Malaysia", "Mexico", 
"Russia", "Saudi Arabia", "Singapore", "South Korea", "Switzerland", 
"Thailand", "Turkey", "United Arab Emirates", "USA", "Vietnam"
), `2008` = c("8241.2", "126.2", "134.6", "310.3", "971.5", "1309.1", 
"246.8", "132.6", "531.7", "135.7", "198.1", "316.6", "241.5", 
"230.1", "286.8", "136.2", "119.6", "89.8", "133.6", "884.0", 
"42.7"), `2013` = c("11230.0", "190.9", "182.0", "345.0", "1664.5", 
"1736.4", "345.8", "237.2", "538.1", "172.0", "286.1", "397.0", 
"332.1", "310.3", "421.4", "269.4", "169.0", "114.3", "198.4", 
"1188.5", "96.9"), `2016` = c("11186.6", "172.8", "166.7", "352.0", 
"1930.3", "1745.5", "417.8", "236.6", "582.7", "171.1", "337.8", 
"258.0", "182.0", "298.6", "448.0", "275.0", "193.1", "128.8", 
"160.3", "1313.3", "158.6"), `2017` = c("12162.3", "203.0", "192.8", 
"370.7", "2018.3", "1879.0", "487.0", "262.2", "617.9", "192.8", 
"362.4", "314.9", "195.1", "324.0", "497.5", "264.7", "208.8", 
"139.0", "177.1", "1368.2", "188.8"), `2018` = c("12881.7", "215.7", 
"205.2", "379.1", "2118.0", "1956.5", "481.9", "273.7", "624.9", 
"209.5", "381.6", "380.3", "250.1", "349.7", "512.9", "262.4", 
"212.2", "142.2", "247.8", "1409.2", "202.3"), `2008-2018` = c("4.6%", 
"5.5%", "4.3%", "2.0%", "8.1%", "4.1%", "6.9%", "7.5%", "1.6%", 
"4.4%", "6.8%", "1.9%", "0.4%", "4.3%", "6.0%", "6.8%", "5.9%", 
"4.7%", "6.4%", "4.8%", "16.8%"), `2013-2018` = c("2.8%", "2.5%", 
"2.4%", "1.9%", "4.9%", "2.4%", "6.9%", "2.9%", "3.0%", "4.0%", 
"5.9%", "-0.9%", "-5.5%", "2.4%", "4.0%", "-0.5%", "4.7%", "4.5%", 
"4.5%", "3.5%", "15.8%"), `2017-2018` = c("5.9%", "6.3%", "6.5%", 
"2.3%", "4.9%", "4.1%", "-1.1%", "4.4%", "1.1%", "8.6%", "5.3%", 
"20.8%", "28.2%", "7.9%", "3.1%", "-0.9%", "1.6%", "2.3%", "39.9%", 
"3.0%", "7.1%"), share = c("100.0%", "1.7%", "1.6%", "2.9%", 
"16.4%", "15.2%", "3.7%", "2.1%", "4.9%", "1.6%", "3.0%", "3.0%", 
"1.9%", "2.7%", "4.0%", "2.0%", "1.6%", "1.1%", "1.9%", "10.9%", 
"1.6%"), `Ranking in 2018` = c("-", "15", "18", "9", "1", "2", 
"6", "11", "4", "17", "7", "8", "13", "10", "5", "12", "16", 
"21", "14", "3", "19")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -21L))


dt2 <- dt %>%
    rename("World\nshare\n2018"="share",
           "World\nRanking\n2018"="Ranking in 2018",
           "10y\n(2008-2018)"="2008-2018",
           "5y\n(2013-2018)"="2013-2018",
           "1y\n(2017-2018)"="2017-2018") %>%
    search_replace( "%", "\\\\%" )



nn <- linebreak(names(dt2), align="c")

pos <- which(dt2$Reporter=="EU28")

ll <- dt2 %>%
    ## mutate_all(linebreak) %>%
    kable("latex", booktabs = T, escape = F,align='rr',
          col.names = nn,caption = "Global imports of goods (billion EUR, \\% )")%>%
    kable_styling(latex_options = c("striped", "hold_position"),
                  full_width = F## , font_size = 7
                 ) %>%
    add_header_above(c(" ", "Value billion EUR" = 5, "Compound annual growth rate"=3)) %>%
    footnote(general=c("\\\\textit{Coverage}: excluding intra-EU trade."## ,""
                     , "\\\\textit{Sources}: Eurostat (Comext, Statistical regime 4), IMF DOTS."),general_title = " ", escape = FALSE) %>%
    row_spec(pos, bold = T)


## df$Noms <- cell_spec(df$Noms, format="latex", 
##                      bold=ifelse(bold_letters == 0, FALSE, TRUE))



writeLines(
  c(
      "\\documentclass{article}",
      "\\usepackage[a4paper, landscape]{geometry}",
      "\\usepackage{caption}",
      "\\usepackage{makecell}",
          "\\usepackage{booktabs}",
"\\usepackage{colortbl, xcolor}",
"\\begin{document}",
"\\thispagestyle{empty}",
"\\captionsetup[table]{labelformat=empty, textfont=bf}",
    ll,
    "\\end{document}"
  ),
  "wrap_kable_fin.tex"
)

tools::texi2pdf("wrap_kable_fin.tex", clean = TRUE)

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