我正在 R markdown 中编译报告,并使用 CSS 进行 HTML 输出。
图形的代码可以工作,我可以为单词“图形”和通过函数生成的图形编号着色。但同样的方法不适用于桌子,我不明白为什么不这样做。
CSS:
/* Custom styles for figure and table captions */
.figure .caption::before{
content: "Figure ";
color: #AA3740; /* Change this to your desired color */
font-weight: bold;
}
.figure .caption .fig-number {
color: #AA3740; /* Same color for the figure number */
font-weight: bold;
}
.figure .caption span {
color: #000000; /* Desired color for the rest of the caption */
}
R 块(其中 ref 部分用于自动分配图形编号):.
```{r figure_1, fig.cap = paste0('<span class="fig-number">', ref("fig:figure_1"), '</span>: Title’)}```
对于我尝试过类似的表,但它似乎不起作用(我正在使用包
flextable
):
CSS:
/* Custom styles for figure and table captions */
.table .caption::before{
content: "Table ";
color: #AA3740; /* Change this to your desired color */
font-weight: bold;
}
.table .caption .tab-number {
color: #AA3740; /* Same color for the figure number */
font-weight: bold;
}
.table .caption span {
color: #000000; /* Desired color for the rest of the caption */
}
R块:
```{r table_1, tab.caption = paste0('<span class="table-number">', ref("tab:table_1"), '</span>: title’)}```
我的表格没有出现标题。
我无法通过
flextable
包获得您想要的内容,因为标题已经插入到 span
元素内,因此您无法在其中添加其他 html 元素(所有内容均逐字呈现)。
但是有了
knitr::kable
表,你可以让它像这样工作:
```{r table_1, tab.cap = paste0('<span class="tab-number">', ref("tab:table_1"), '</span>: Title')}
knitr::kable(head(iris))
```
以及以下 CSS:
.table caption::before{
content: "Table ";
color: #AA3740; /* Change this to your desired color */
font-weight: bold;
}
.table caption .tab-number {
color: #AA3740; /* Same color for the figure number */
font-weight: bold;
}
.table caption {
color: #000000; /* Desired color for the rest of the caption */
}