【问题标题】:Centering Rmarkdown knitrbootstrap Report居中 Markdown knitr bootstrap 报告
【发布时间】:2022-01-04 02:01:49
【问题描述】:

找到this package called knitrBootstrap,这是为了在Rmarkdown中报告时允许Bootstrap样式的网页。

注意:我使用的是klippykableExtraknitrBootstrap

我的问题是,当呈现时不会使整个报告居中,它会卡在一侧。而且文档的标题也没有显示?有什么建议可以让这个 HTML 页面更“完整”吗?因为我可以在 Rmarkdown 中插入直接的 HTML 代码,所以我添加了 HTML 标记

---
output:
  knitrBootstrap::bootstrap_document:
    title: "Test file"
    theme: united
    highlight: sunburst
---

```{r}
library(kableExtra)
library(klippy)
library(knitrBootstrap)
```

```{r echo=FALSE, include=TRUE, out.width="100%"}
mpg_list <- split(mtcars$mpg, mtcars$cyl)
disp_list <- split(mtcars$disp, mtcars$cyl)
inline_plot <- data.frame(cyl = c(4, 6, 8), mpg_box = "",     mpg_hist = "",
                          mpg_line1 = "", mpg_line2 = "",
                          mpg_points1 = "", mpg_points2 = "",     mpg_poly = "")
inline_plot %>%
  kbl(booktabs = TRUE) %>%
  kable_paper(full_width = FALSE) %>%
  column_spec(2, image = spec_boxplot(mpg_list)) %>%
  column_spec(3, image = spec_hist(mpg_list)) %>%
  column_spec(4, image = spec_plot(mpg_list, same_lim = TRUE))     %>%
  column_spec(5, image = spec_plot(mpg_list, same_lim =     FALSE)) %>%
  column_spec(6, image = spec_plot(mpg_list, type = "p")) %>%
  column_spec(7, image = spec_plot(mpg_list, disp_list, type =     "p")) %>%
  column_spec(8, image = spec_plot(mpg_list, polymin = 5))
```

【问题讨论】:

    标签: html bootstrap-4 r-markdown knitr


    【解决方案1】:

    我似乎找不到大量关于您使用的格式的文献。但是,我确实注意到当屏幕尺寸改变时它不会改变尺寸。这一切都只是设置为一个最终大小。话虽如此,该表认为它是居中的。实际上,它被格式化为“适合”内容,但表格被设置为填充一个空间,以便外部空间在正文中居中,但表格在该可用空间中左对齐。最重要的是,body 的最大宽度设置为 36em。这就是它看起来左对齐的原因。

    我知道,一清二楚。叹息。

    我可以帮助改进它,但不同的输出格式可能是更好的选择。几乎所有我试图让表格变大的方法都会破坏绘图的 SVG(扭曲它们)。

    这有效,但我不知道果汁是否值得挤压。

    在块之间添加这些样式并保持您的代码相同。

    <style>
    body {
      max-width: 100%;          // 36 em isn't working for me
    }
    table{
      width: 924px !important;
      height: auto;
    }
    tr {
      height: 4em;
      width: 924px !important;  // 28 + (7*128) (for the 8 columns)
    }
    td {
      vertical-align: middle !important;
      padding-bottom: 0px !important;
    }
    svg {
      width: 110%;
      height: auto;   // keep the aspect ratio
    }
    thead > tr *:not(:first-child) {
      width: 128px;  // only set here, if set to all td, it blows the svg
    }
    </style>
    

    如果您有任何问题,请告诉我。

    通过填充可用空间来居中,而不居中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多