簡體   English   中英

R Notebook:並排放置 knitr::kable 表?

[英]R Notebook: place knitr::kable tables side-by-side?

我正在 R Notebook 中編寫一些圖形和表格,並且我想並排放置一些表格。 我正在將筆記本編織成 html。 我目前擁有的代碼(如下)有效,但兩個表都向左對齊。 我真正想要的是讓它們並排出現但也居中。 請問有什么建議嗎? dt_tot 和 dt_tot_week 是 data.tables。

knitr::kable(dt_tot, "html", caption = caption) %>%
  kableExtra::kable_styling(bootstrap_options = c("hover"),
                            full_width = FALSE, position = "float_left")

knitr::kable(dt_tot_week, "html", caption = caption) %>%
kableExtra::kable_styling(bootstrap_options = c("hover"),
                          full_width = FALSE, position = "float_left")

如果你正在編織 HTML,你應該能夠使用knitr::kables 這給了我兩個並排的表:

library(tidyverse)
library(kableExtra)

knitr::kables(list(
  kable(caption = "Left Table",
    starwars %>%
      count(species) %>%
      filter(n > 1)
    ) %>% kable_styling(),
    kable(caption = "Right Table",
      starwars %>%
        count(homeworld) %>%
        filter(n > 1)
    ) %>% kable_styling()
    
  )
) %>% kable_styling()

您只需要將 dt_tot_week 形成的 table 的位置更改為 float_right 而不是 float_left。 我敢肯定那一定是您的代碼中的錯字。

knitr::kable(dt_tot, "html", caption ="left Tbl") %>%
kableExtra::kable_styling(bootstrap_options = c("hover"),
                            full_width = FALSE, position = "float_left")

knitr::kable(dt_tot_week, "html", caption ="right Tbl") %>%
kableExtra::kable_styling(bootstrap_options = c("hover"),
                          full_width = FALSE, position = "float_right")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM