阻止 HTML 表格在 Quarto 中使用整个页面宽度

huangapple go评论53阅读模式
英文:

Prevent HTML table to use full page width in Quarto

问题

我想在Quarto中使用HTML表格,但我希望它不要使用整个页面的宽度。以下是一个可重现的示例:

---
title: "HTML tables in Quarto"
format: html
---

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 1

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 2 {tbl-colwidths=" [75,25] "}

输出:

阻止 HTML 表格在 Quarto 中使用整个页面宽度

如您所见,表格1是正常的,可以看到它占用了整个页面的宽度。表格2具有tbl-colwdiths选项,但这不会使表格的宽度变小,仍然占满整个页面宽度。因此,我想知道是否有人知道如何阻止HTML表格在Quarto中使用整个页面的宽度?

英文:

I would like to use HTML tables in Quarto, but I would like to prevent it using the full page width. Here is a reproducible example:

---
title: "HTML tables in Quarto"
format: html
---

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 1

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 2 {tbl-colwidths="[75,25]"}

Output:

阻止 HTML 表格在 Quarto 中使用整个页面宽度

As we can see, table 1 is normal and you can see it takes the full page width. Table 2 has tbl-colwdiths options, but this doesn't make the table smaller in width and is also the full page width. So I was wondering if anyone knows how to prevent the HTML table to use the full page width in Quarto?

答案1

得分: 3

以下是翻译好的部分:

也许可以使用CSS网格系统

---
title: "在Quarto中使用HTML表格"
format: html
---
| 水果   | 价格   |
|--------|--------|
| 苹果   | 2.05   |
| 梨     | 1.37   |
| 橙子   | 3.09   |

表格 1

::: {.grid}
::: {.g-col-7}
| 水果   | 价格   |
|--------|--------|
| 苹果   | 2.05   |
| 梨     | 1.37   |
| 橙子   | 3.09   |

表格 2

:::
:::

阻止 HTML 表格在 Quarto 中使用整个页面宽度

编辑:如果要居中,可以利用CSS网格中的默认十二列,例如:

::: {.grid}
::: {.g-col-2}
:::
:::

::: {.g-col-8}
| 水果   | 价格   |
|--------|--------|
| 苹果   | 2.05   |
| 梨     | 1.37   |
| 橙子   | 3.09   |

表格 2

:::
:::

::: {.g-col-2}
:::
:::
英文:

Maybe use the css grid system:

---
title: "HTML tables in Quarto"
format: html
---

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 1

::: {.grid}

::: {.g-col-7}

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 2 

:::
:::

阻止 HTML 表格在 Quarto 中使用整个页面宽度

Edit: If you want to center, you could utilize the default of twelve columns in the css grid, e.g.

::: {.grid}

::: {.g-col-2}
:::


::: {.g-col-8}

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Table 2 

:::

::: {.g-col-2}
:::

:::

答案2

得分: 2

使用.columns div 来实现列布局的一个可能选项

---
title: "Quarto中的HTML表格"
format: html
engine: knitr
---

:::: {.columns}
::: {.column width="70%"}

| 水果    | 价格   |
|--------|--------|
| 苹果    | 2.05   |
| 梨      | 1.37   |
| 橙子    | 3.09   |

: 表格 1

:::
::::

```{css, echo=FALSE}
.center-table table {
  width: 50%;
  margin-left: auto;
  margin-right: auto;
}

::: {.center-table}

水果 价格
苹果 2.05
1.37
橙子 3.09

: 表格 2

:::


<hr>

[![输入图片描述][1]][1]

[1]: https://i.stack.imgur.com/yZBAU.png
```

<details>
<summary>英文:</summary>

One possible option to use `.columns` div to get column layout


title: "HTML tables in Quarto"
format: html
engine: knitr

:::: {.columns}
::: {.column width="70%"}

fruit price
apple 2.05
pear 1.37
orange 3.09

: Table 1

:::
::::

.center-table table {
  width: 50%;
  margin-left: auto;
  margin-right: auto;
}

::: {.center-table}

fruit price
apple 2.05
pear 1.37
orange 3.09

: Table 2

:::



&lt;hr&gt;

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/yZBAU.png

</details>



huangapple
  • 本文由 发表于 2023年2月7日 01:22:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定