如何格式化HTML表不需要在渲染的rmarkDown中滚动栏?

发布于 2025-01-29 06:52:55 字数 712 浏览 3 评论 0原文

我有我保存了gtsavesave_kable的表。您如何格式化您保存和调用的HTML表的尺寸?我想在编织降价(HTML输出)中查看桌子时不必使用滚动条。

现在,桌子呈现rmarkDown后,桌子很小,您必须使用滚动条向下滚动,然后在页面上看不到整个桌子。

我非常感谢任何帮助使桌子看起来可读的帮助。

我的rmarkDown看起来像这样:

library(tidyverse)
library(gt)
library(knitr)
Library(kableExtra)

table_gt_tbl %>% gtsave(“table_gt_tbl”, path = “PATH”)

![](path/table_gt_tbl.html“狗繁殖”)



music %>% select(ID, location, address, music_type) %>% knitr::kable() %>% kable_styling(latex_options = c(“scale_down”, “HOLD_position”) %>% kableExtra::save_kable(“PATH/music.html”)

![](path/path/music.html“音乐位置”)>

I have tables that I’ve saved with gtsave and save_kable. How do you format the sizes of html tables you’ve saved and called? I want to not have to use the scroll bar when looking at the tables in my knitted markdown (html output).

The tables right now, after rendering the rmarkdown, are small and you have to use scroll bar to scroll downwards and to the side, you can’t see the whole table on the page.

I’d very much appreciate any help in making the tables look readable.

My rmarkdown looks like this:

library(tidyverse)
library(gt)
library(knitr)
Library(kableExtra)

table_gt_tbl %>% gtsave(“table_gt_tbl”, path = “PATH”)

![](PATH/table_gt_tbl.html “dog breeds”)



music %>% select(ID, location, address, music_type) %>% knitr::kable() %>% kable_styling(latex_options = c(“scale_down”, “HOLD_position”) %>% kableExtra::save_kable(“PATH/music.html”)

![](PATH/music.html “music locations”)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡離愁欲言轉身 2025-02-05 06:52:55

您的滚动条可能会自动添加,因为输出html_document添加了我认为是 bobnoxious 边距。

我建议您首先添加以下CSS。这可以进入RMD的任何地方,只需确保它不在块中即可。

<style>
.main-container {
  max-width: unset;
}
</style>

如果这还不够,请尝试增加高度和宽度。

![](PATH/table_gt_tbl.html “dog breeds”){width=100% height=100%}

如果您用R调用表,则无需设置高度和宽度。如果您像示例中一样使用表,作为保存的.html文件,您可能需要两者都需要。

这是我用来测试的

---
title: "Untitled"
author: "me"
date: '2022-05-17'
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
library(gt)
library(tidyverse)
data(gtcars)
```

<style>
.main-container {
  max-width: unset;
}
</style>

# wuz up?

```{r gts}

gtcars %>%
  gt(rowname_col = "model") %>%
  tab_stubhead(label = "car")

```

## TELL ME MORE!!! 

```{r yaaaTablezzz}

gtcars %>%
  slice(1:5) %>%
  gt(rowname_col = "model") %>%
  tab_stubhead(label = "car") %>% 
  gtsave("table_gt_tbl.html", path = "../_html")

```

![](../_html/table_gt_tbl.html){width=100% height=100%}

Your scrollbars are probably automatically added because the output html_document adds what I think are obnoxious margins.

I would suggest that you start by adding the following CSS. This can go anywhere in your RMD, just make sure it's not in a chunk.

<style>
.main-container {
  max-width: unset;
}
</style>

If that isn't enough, try adding height and width.

![](PATH/table_gt_tbl.html “dog breeds”){width=100% height=100%}

If you call the tables with R, you won't need to set the height and width. If you use the tables as you did in your example, as a saved .HTML file, you will probably need both.

Here's what I used to test this

---
title: "Untitled"
author: "me"
date: '2022-05-17'
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
library(gt)
library(tidyverse)
data(gtcars)
```

<style>
.main-container {
  max-width: unset;
}
</style>

# wuz up?

```{r gts}

gtcars %>%
  gt(rowname_col = "model") %>%
  tab_stubhead(label = "car")

```

## TELL ME MORE!!! 

```{r yaaaTablezzz}

gtcars %>%
  slice(1:5) %>%
  gt(rowname_col = "model") %>%
  tab_stubhead(label = "car") %>% 
  gtsave("table_gt_tbl.html", path = "../_html")

```

![](../_html/table_gt_tbl.html){width=100% height=100%}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文