RMD、PDF 输出中的样式参考标题标签字体

Style reference caption label font in RMD, PDF output

无法找到与此问题完全匹配的答案,所以请继续。我正在尝试设置 automatically-generated cross-reference 标题标签字体的样式,例如'Table 1' 或 'Figure 2' 用于从 RStudio Server 中的 RMD 文件生成的 PDF 输出。目前,我只能设置实际字幕文本的样式。

我的RMD文件设置如下:

output: 
  bookdown::pdf_document2
header-includes:
  - \usepackage{lscape}
bibliography: Interpolation.bib
link-citations: yes

设置块包括:

knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
knitr::opts_chunk$set(dpi=500,fig.width=7)
knitr::opts_chunk$set(dev = 'pdf')

产生一个table:


    ```{r top-models-summary-table, echo=FALSE, echo=FALSE}
    df %>%  
      mutate_all(kableExtra::linebreak) %>%
      kable("latex", booktabs = T, escape = F, align='l',
                 col.names = linebreak(c('Interpolation\nMethod',
                            'Run num.',
                            'Train-Test\nSplit Approach',
                            'Mean Unmasked\nTest RMSE',
                            'Mean Masked\nTest RMSE',
                            'SD Unmasked\nTest RMSE',
                            'SD Masked\nTest RMSE'),
                            align = "c"),
                 caption="\small\textit{My caption text}") 

这会产生如下输出:

标题标签和文本不匹配...我猜想可以在 header 中设置标题标签的样式,但找不到。

R session 信息:

    R version 3.6.3 (2020-02-29)
    Platform: x86_64-pc-linux-gnu (64-bit)
    Running under: Ubuntu 20.04.3 LTS
    
    Matrix products: default
    BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3
    
    locale:
     [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
     [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
     [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
    [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
    
    attached base packages:
    [1] parallel  grid      stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
     [1] kableExtra_1.3.1    RefManageR_1.3.0    future.apply_1.6.0  doParallel_1.0.16  
     [5] iterators_1.0.13    foreach_1.5.1       gridExtra_2.3       furrr_0.2.2        
     [9] future_1.21.0       purrr_0.3.4         viridis_0.5.1       viridisLite_0.3.0  
    [13] patchwork_1.1.1     mgcv_1.8-34         nlme_3.1-152        interp_1.0-33      
    [17] fields_11.6         spam_2.6-0          dotCall64_1.0-1     automap_1.0-14     
    [21] raster_3.4-5        sp_1.4-5            gdalUtils_2.0.3.2   dplyr_1.0.2        
    [25] stars_0.4-3         sf_0.9-8            abind_1.4-5         stringr_1.4.0      
    [29] mapview_2.9.0       randomForest_4.6-14 caret_6.0-86        lattice_0.20-41    
    [33] e1071_1.7-4         reshape2_1.4.4      ggforce_0.3.2       ggplot2_3.3.3      
    [37] gstat_2.0-6         data.table_1.14.0  
    
    loaded via a namespace (and not attached):
      [1] R.utils_2.10.1       tidyselect_1.1.0     htmlwidgets_1.5.2    ggsflabel_0.0.1     
      [5] ranger_0.12.1        pROC_1.17.0.1        munsell_0.5.0        codetools_0.2-18    
      [9] units_0.7-1          misc3d_0.9-0         withr_2.4.1          colorspace_2.0-0    
     [13] highr_0.8            knitr_1.36           rstudioapi_0.13      stats4_3.6.3        
     [17] ggsignif_0.6.1       Rttf2pt1_1.3.8       listenv_0.8.0        RgoogleMaps_1.4.5.3 
     [21] aqp_1.29             polyclip_1.10-0      mlrMBO_1.1.5         farver_2.1.0        
     [25] mlr_2.18.0           parallelly_1.24.0    vctrs_0.3.7          generics_0.1.0      
     [29] ipred_0.9-9          xfun_0.22            rayshader_0.19.2     R6_2.5.0            
     [33] RJSONIO_1.3-1.4      bitops_1.0-6         lhs_1.1.1            reshape_0.8.8       
     [37] scales_1.1.1         nnet_7.3-15          gtable_0.3.0         egg_0.4.5           
     [41] mco_1.15.6           globals_0.14.0       lwgeom_0.2-5         DiceKriging_1.6.0   
     [45] timeDate_3043.102    rlang_0.4.10         BBmisc_1.11          splines_3.6.3       
     [49] extrafontdb_1.0      lazyeval_0.2.2       GSIF_0.5-5.1         rstatix_0.7.0       
     [53] rgdal_1.5-23         ModelMetrics_1.2.2.2 broom_0.7.5          checkmate_2.0.0     
     [57] rgl_0.107.14         yaml_2.2.1           crosstalk_1.1.0.1    backports_1.2.1     
     [61] fasterize_1.0.3      extrafont_0.17       tcltk_3.6.3          tools_3.6.3         
     [65] lava_1.6.8.1         bookdown_0.24        ellipsis_0.3.1       RColorBrewer_1.1-2  
     [69] Rcpp_1.0.6           plyr_1.8.6           progress_1.2.2       base64enc_0.1-3     
     [73] ggspatial_1.1.4      parallelMap_1.5.0    classInt_0.4-3       smoof_1.6.0.2       
     [77] prettyunits_1.1.1    ggpubr_0.4.0         rpart_4.1-15         deldir_1.0-6        
     [81] ParamHelpers_1.14    zoo_1.8-9            ggmap_3.0.0.903      haven_2.3.1         
     [85] cluster_2.1.0        colorRamps_2.3       leafem_0.1.3         magrittr_2.0.1      
     [89] scattermore_0.7      pixmap_0.4-12        openxlsx_4.2.3       spacetime_1.2-4     
     [93] ggnewscale_0.4.5     smoothr_0.1.2        hms_0.5.3            evaluate_0.14       
     [97] XML_3.99-0.3         leaflet_2.0.3        jpeg_0.1-8.1         rio_0.5.26          
    [101] readxl_1.3.1         compiler_3.6.3       tibble_3.0.4         maps_3.3.0          
    [105] KernSmooth_2.23-18   plotKML_0.6-1        crayon_1.4.1         R.oo_1.24.0         
    [109] htmltools_0.5.1.1    tidyr_1.1.2          lubridate_1.7.10     DBI_1.1.1           
    [113] tweenr_1.0.2         RSAGA_1.3.0          tuneRanger_0.5       MASS_7.3-53.1       
    [117] wesanderson_0.3.6    Matrix_1.3-2         car_3.0-10           cli_2.4.0           
    [121] R.methodsS3_1.8.1    shapefiles_0.7       gower_0.2.2          forcats_0.5.0       
    [125] pkgconfig_2.0.3      foreign_0.8-75       plotly_4.9.2.1       terra_1.4-9         
    [129] recipes_0.1.15       xml2_1.3.2           webshot_0.5.2        prodlim_2019.11.13  
    [133] bibtex_0.4.3         rvest_0.3.6          digest_0.6.27        rmarkdown_2.11      
    [137] cellranger_1.1.0     fastmatch_1.1-0      intervals_0.15.2     curl_4.3            
    [141] satellite_1.0.2      lifecycle_1.0.0      dismo_1.3-3          jsonlite_1.7.2      
    [145] carData_3.0-4        pillar_1.4.7         httr_1.4.2           plotrix_3.8-1       
    [149] survival_3.2-10      glue_1.4.2           xts_0.12.1           zip_2.1.1           
    [153] FNN_1.1.3            png_0.1-7            plot3D_1.3           class_7.3-18        
    [157] stringi_1.5.3        snowfall_1.84-6.1

此处代表:

---
title: "Title"
author: "BGH"
date: "10/03/2021"
output: 
  bookdown::pdf_document2
header-includes:
  - \usepackage{lscape}
link-citations: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
knitr::opts_chunk$set(dpi=500,fig.width=7)
knitr::opts_chunk$set(dev = 'pdf')

library(kableExtra)
library(dplyr)

```
My main body text. Check out Table \@ref(tab:my-table) for the issue.

```{r my-table, echo=FALSE, echo=FALSE}
head(iris) %>%  
  mutate_all(kableExtra::linebreak) %>%
  kable("latex", booktabs = T, escape = F, align='l',
             caption="\small\textit{My table caption}")

```

您可以使用 caption 包来自定义标题的字体:

---
title: "Title"
author: "BGH"
date: "10/03/2021"
output: 
  bookdown::pdf_document2:
    keep_tex: true
header-includes:
  - \usepackage{lscape}
  - \usepackage{caption}
  - \captionsetup{font={it,small}}
link-citations: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
knitr::opts_chunk$set(dpi=500,fig.width=7)
knitr::opts_chunk$set(dev = 'pdf')

library(kableExtra)
library(dplyr)

```
My main body text. Check out Table \@ref(tab:my-table) for the issue.

```{r my-table, echo=FALSE, echo=FALSE}
head(iris) %>%  
  mutate_all(kableExtra::linebreak) %>%
  kable("latex", booktabs = T, escape = F, align='l',
             caption="My table caption")

```