如何将源注释与gt表中的表对齐?

问题描述 投票:0回答:3

我正在使用 R markdown 生成 pdf 文档,使用 gt() 制作一个表格,底部带有源注释。由于某种原因,源注释未与表格居中对齐。如何使其与表格对齐?

这是我编织PDF文档时出现的结果,源注释位于左侧并且未与表格居中。

这是我的数据框:

test_df<-
    structure(list(Year = c("2010", "2015", "2020"), Lehigh_County = c(350008, 
359689, 374557), Northampton_County = c(297941, 300264, 312951
), Lehigh_Valley = c(647949, 659953, 687508)), row.names = c(NA, 
-3L), class = c("tbl_df", "tbl", "data.frame"))

这是将其制作成gt表的代码:

    test_df %>% 
  gt() %>% 
  tab_header(
    title = "Lehigh Valley Population Forecast",
    subtitle = "2020 - 2050"
  ) %>% 
  cols_label(
    Lehigh_County = "Lehigh County",
    Northampton_County = "Northamp. County",
    Lehigh_Valley = "Lehigh Valley"
  ) %>% 
  tab_source_note(source_note = "U.S. Census / REMI Forecasts") %>% 
  fmt_number(columns = c(Lehigh_County, Northampton_County, Lehigh_Valley), sep_mark = ",", decimals = 0)

当我生成表格时,它看起来是正确的,但是当我编织时,源注释会向左移动。有什么建议吗?

r r-markdown gt
3个回答
0
投票

这是一个快速技巧,让您可以继续工作而不必担心格式,但如果您渲染为

html_document
,您可以“打印到 pdf”,这在紧要关头可以实现一些 HTML 样式。


0
投票

我没有这样的问题,但你可以尝试使用“tab_style”显式设置source_note的样式,其中“location”指向源注释。

tab_style(style = cell_text(align = "left"),locations = cells_source_notes())

它应该强制 GT 重写源注释字段。 希望有帮助。


0
投票

尝试

as_raw_html()
。它对我有用。

table |>
  gt( ) |>
  as_raw_html( )
© www.soinside.com 2019 - 2024. All rights reserved.