这是this question中的一个后续问题,我在其中询问了如何在Quarto v1.3中 suppress 表的 bootstrap 布局.解决方案是在块选项中添加#| output: asis,然后在代码末尾添加|> print_html(). 这对于正常使用非常有效.然而,当在标注块中使用时,将表格打印为HTML似乎会禁用标注块. 我找到了一种解决此问题的方法,即省略|> print_html(),如下所示:

---
title: Table style
format: html
---

::: {.callout-important}

Some text about the table

```{r}
#| echo: false
#| warning: false
#| output: asis

library(huxtable)

t1 <-  matrix(c("",            "",   "Success", "",     "", 
                "",            "",   "no",      "yes",  "", 
                "Medication",  "A",  4,         2,      6,
                "",            "B",  2,         5,      7,
                "",            "",   6,         7,      13),
              nrow = 5, byrow = T)

huxtable::as_hux(t1) |> 
  set_bottom_border(row = c(2,4), col = 2:5) |>
  set_bottom_border(row = c(1,5), col = c(3,4)) |>
  
  set_right_border(row = 2:5, col = c(2,4)) |> 
  set_right_border(row = c(3,4), col = c(1,5)) |> 
  
  set_bold(row = 1, col = 3) |> 
  set_bold(row = 3, col = 1) |> 
  
  set_col_width(col = everywhere, 0.2)
```
:::

Again, this works fine, but it generates a grey line above the table, which I'd rather not have: I found, that this is caused by the last code-line set_col_width(), but I absolutely need to set the col-width because the table looks ridiculous without.

有什么办法可以go 掉那条灰色水平线吗?

推荐答案

虽然我不知道这条灰色线条的原因,但您可以使用一些css将其删除:

---
title: Table style
format: html
---

```{css}
#| echo: false
.huxtable {
    border-top: hidden;
}
```

::: {.callout-important}

Some text about the table

```{r}
#| echo: false
#| warning: false
#| output: asis

library(huxtable)

t1 <-  matrix(c("",            "",   "Success", "",     "", 
                "",            "",   "no",      "yes",  "", 
                "Medication",  "A",  4,         2,      6,
                "",            "B",  2,         5,      7,
                "",            "",   6,         7,      13),
              nrow = 5, byrow = T)

huxtable::as_hux(t1) |> 
  set_bottom_border(row = c(2,4), col = 2:5) |>
  set_bottom_border(row = c(1,5), col = c(3,4)) |>
  
  set_right_border(row = 2:5, col = c(2,4)) |> 
  set_right_border(row = c(3,4), col = c(1,5)) |> 
  
  set_bold(row = 1, col = 3) |> 
  set_bold(row = 3, col = 1) |> 
  
  set_col_width(col = everywhere, 0.2)
```
:::

enter image description here

R相关问答推荐

如何判断某列中由某些行组成的百分比

是否可以 Select 安装不带文档的R包以更有效地存储?

具有多个依赖变量/LHS的逻辑模型

如何使用shinyChatR包配置聊天机器人

如何删除R中除某些特定名称外的所有字符串?

在R中创建一个包含转换和转换之间的时间的列

derrr summarise每个组返回多行?

如何使用R对每组变量进行随机化?

如何直接从Fortran到R的数组大小?

如何改变时间图R中的悬停信息?

R函数,用于生成伪随机二进制序列,其中同一数字在一行中不出现超过两次

汇总数据的Sheffe检验的P值(平均值和标准差)

我将工作代码重构为一个函数--现在我想不出如何传递轴列参数

删除在R中的write.table()函数期间创建的附加行

我需要使用ggplot2制作堆叠条形图

Data.table::Shift type=允许扩展数据(&Q;LAG&Q;)

如何在矩阵图中按标准对数据进行分组以绘制矩阵

如何捕获这个shiny 的、可扩展的react 性用户输入矩阵作为另一个react 性对象,以便进一步操作?

如何将一列相关性转换为R中的相关性矩阵

打印的.txt文件,将值显示为&Quot;Num&Quot;而不是值