Использование r + gt () + Quarto для отображения отчета HTML. Я хочу уменьшить прокладку вокруг всех трех таблиц до 0px, как показано ниже в красной коробке. Это было сделано с использованием идентификатора div , который меняется каждый раз, когда запускается отчет Quarto, поэтому мне нужно решение, которое будет нацелено на них без использования идентификатора div .
Я думал, что это будет вопрос CSS, но так далеко все мои решения CSS терпят неудачу, поэтому я не знаю, поможет ли что -то в gt () или Quarto . надое и надоеволокоптом в следующем от 10 пикселей до 0PX он работает как предполагалось: < /p>
Код: Выделить всё
... lots of other stuff ...
< /code>
Однако, если я попробую выбрать его с помощью своих styles.css, я получаю смешанные результаты. Каждая попытка выбирает их, но не будет уменьшаться до 10px. Однако я могу увеличить прокладку, и это будет работать. Вот мои styles.css с примечаниями: < /p>
/* CSS */
.gt_table {
margin-top: 0px !important;
margin-bottom: 0px !important;
}
/* If padding >10 it will increase the padding, but not decrease */
div.cell-output-display{
padding-top: 0px !important;
padding-bottom: 0px !important;
border: 2px dotted green;
}
/* This will reduce the padding as intended*/
/* But the div ids change when I re-run the report with a different date */
#rwxpuyzumb{
padding-top: 0px !important;
padding-bottom: 0px !important;
border: 2px solid red;
}
/* This will target the correct table, but also only increases padding */
.cell-output-display:nth-of-type(2){
padding-top: 0px !important;
padding-bottom: 50px !important;
border: 2px solid yellow;
}
/* This will target the correct table, but also only increases padding */
.cell-output-display:nth-of-type(3){
padding-top: 0px !important;
padding-bottom: 0px !important;
border: 2px solid blue;
}
---
title: "gt_padding"
format:
html:
css: styles.css
editor_options:
chunk_output_type: console
---
```{r}
#| include: false
library(dplyr)
library(gt)
dat as_tibble(rownames = "car") |> head(4)
tab1 select(car,2:3) |> gt()
tab2 select(car,4:7) |> gt()
tab3 select(car,8:11) |> gt()
```
```{r}
#| echo: false
tab1
tab2
tab3
```
< /code>
Редактировать: я также поместил необработанные HTML и CSS на GIT, если это используется. Найдено здесь: https://github.com/stxlen/code_share
Подробнее здесь: https://stackoverflow.com/questions/794 ... rto-or-css
Мобильная версия