1

我在 Rmarkdown Tufte 样式的 HTML 中包含 gt 表。我想在主列的中心对齐 gt 表,而不是在跨越主列和边距的 HTML 的中心。我尝试使用 fig.align knitr 选项以及 tab.align 命令。这是一个带有 rmd 的 repo,它显示了问题:https ://github.com/cassidybargell/gt-tufte 。gt 表跨越主列和边距。

Tufte-HTML 中使用的 gt 表的示例代码:

小标题(主题=“乔”,
       ytreat = "13",
       ycontrol = "9",
       ydiff = "+4") %>%  
  gt()
4

2 回答 2

0

另一种方法是定义一个钩子函数:

knitr::knit_hooks$set(gtbl = function(before, options){
if (before) {
paste( '<style> .gt_table {width: 100% !important;} </style>',
       '<div class="figure"><p class="caption marginnote shownote">', 
       options$fig.cap, 
       '</p>', 
       sep="")
} else { "</div>" }
})

块内。然后在需要 gt 表时可以使用块选项 gtbl,例如:

```{r gtbl=TRUE, fig.cap="*Table 1* Energy Trends"}
tblTrends()
```

其中 fig.cap 提供右对齐的标题。

钩子函数记录在rmarkdown 食谱中

于 2021-02-20T13:59:59.250 回答
0

制作自己的 css 文件是修复它的一种方法。以下是代码行:

.gt_table {
  margin-left: 0 !important;
  margin-right: 0 !important;
  width: 55% !important;
}

感谢姚东的帮助!!

于 2020-06-28T22:41:53.620 回答