使quarto HTML文档使用完整的窗口宽度

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

Making quarto html documents use the full window width

问题

我正在使用R创建一个quarto HTML文档,并将其发布到rpubs.com上。该文档仅使用窗口的中间部分,留下左侧和右侧的三分之一为空白。我正在展示一个表格,但它没有从最左侧开始,因此部分内容被截断。我该如何告诉quarto使用整个窗口?以下是一个可重现的示例。

  1. ---
  2. title: "Test2"
  3. author: "Philip Smith"
  4. format: html
  5. html:
  6. page-layout: custom
  7. editor: visual
  8. code-fold: true
  9. link-external-icon: true
  10. knitr:
  11. opts_chunk:
  12. collapse: true
  13. comment: "#>"
  14. R.options:
  15. knitr.graphics.auto_pdf: true
  16. ---
  17. ```{r set-options, echo=FALSE, warning=FALSE, cache=FALSE}
  18. library(lubridate)
  19. library(gt)
  20. FdfT <- structure(list(Name = c("LFS participation rate", "LFS employment rate",
  21. "LFS unemployment rate", "Job vacancy rate", "LFS payroll", "LFS payroll employment",
  22. "LFS payroll average hours worked", "LFS payroll average hourly earnings",
  23. "SEPH payroll", "SEPH payroll employment", "SEPH payroll average hours worked",
  24. "SEPH payroll average hourly earnings", "LFS payroll", "LFS payroll employment",
  25. "LFS payroll average hours worked", "LFS payroll average hourly earnings",
  26. "SEPH payroll", "SEPH payroll employment", "SEPH payroll average hours worked",
  27. "SEPH payroll average hourly earnings"), V1 = c(65.4, 61.5, 6,
  28. 5.6, 8.9, 5.8, 0.3, 2.7, 9.2, 6.8, -0.3, 2.3, 0.8, 0.3, 0.1,
  29. 0.4, 1.3, 0.6, 0.6, 0.1), V2 = c(65, 60.8, 6.5, 5.4, 7.7, 5.8,
  30. -0.6, 2.3, 9.3, 7.8, -0.6, 2, -0.2, -1.5, 0.4, 0.9, 0.9, 0.1,
  31. 0, 0.9), V3 = c(65.4, 61.8, 5.5, 5.3, 9.5, 6.3, 0, 3.1, 10.1,
  32. 8, -0.6, 2.5, 1.9, 2.3, -0.3, -0.1, 0.8, 0.7, 0, 0), V4 = c(65.4,
  33. 61.9, 5.3, 5.7, 9.1, 5.1, 0.3, 3.5, 11.8, 7.2, -0.6, 4.9, 0.7,
  34. 0.3, 0.1, 0.3, 2.2, 0.8, -0.3, 1.7), V5 = c(65.3, 61.9, 5.2,
  35. 5.7, 9.3, 6.3, -0.5, 3.3, 10.2, 7, -1.2, 4.3, -0.2, 0, -0.6,
  36. 0.4, 0.2, 0.7, 0, -0.4), V6 = c(65.3, 61.9, 5.1, 5.7, 10.9, 7.2,
  37. -0.6, 3.9, 11.5, 8.6, -0.9, 3.5, 1.2, 0.2, 0.2, 0.8, -0.4, 0,
  38. -0.3, -0.3), V7 = c(64.9, 61.7, 4.9, 5.6, 11.3, 5.2, 0.6, 5.2,
  39. 11.2, 7.8, -0.6, 3.9, 1.3, 0.1, 0.5, 0.7, 1, 0.8, 0, 0.4), V8 = c(64.7,
  40. 61.6, 4.9, 5.5, 10.5, 4.2, 0.9, 5.2, 9, 5.9, -0.6, 3.3, 0, -0.4,
  41. -0.1, 0.4, 0.1, 0.1, 0, -0.1), V9 = c(64.8, 61.3, 5.4, 5.3, 9.4,
  42. 3.5, 0.3, 5.4, 9.2, 5.5, 0, 3.6, 0.2, -0.1, -0.4, 0.6, 0.8, 0,
  43. 0, 0.9), V10 = c(64.7, 61.3, 5.2, 5.2, 8.5, 2.6, 0.6, 5.2, 9.1,
  44. 5.5, -0.6, 3.8, 0.5, 0.2, 0.3, 0, 0.8, 0.5, -0.3, 0.4), V11 = c(64.9,
  45. 61.6, 5.2, 4.9, 8.8, 2.8, 0.3, 5.5, 7.9, 4.7, -1.2, 4.1, 1.1,
  46. 0.5, -0.1, 0.7, -0.6, 0, -0.6, 0.1), V12 = c(64.8, 61.5, 5.1,
  47. NA, 8.3, 2, 0.5, 5.6, NA, NA, NA, NA, 0.7, 0, 0.3, 0.5, NA, NA,
  48. NA, NA), V13 = c(65, 61.8, 5, NA, 7.7, 2.
  49. <details>
  50. <summary>英文:</summary>
  51. I am creating a quarto html document using R and publishing it to the web at rpubs.com. The document uses only the middle third of the window and leaves the left and right thirds blank. I am showing a table but it is not started on the far left side and as a result it is cut off part way through. How can I tell quarto to use the full window? Here is a reproducible example.

title: "Test2"
author: "Philip Smith"
format: html
html:
page-layout: custom
editor: visual
code-fold: true
link-external-icon: true
knitr:
opts_chunk:
collapse: true
comment: "#>"
R.options:
knitr.graphics.auto_pdf: true---

  1. ```{r set-options, echo=FALSE, warning=FALSE, cache=FALSE}
  2. library(lubridate)
  3. library(gt)
  4. FdfT &lt;- structure(list(Name = c(&quot;LFS participation rate&quot;, &quot;LFS employment rate&quot;,
  5. &quot;LFS unemployment rate&quot;, &quot;Job vacancy rate&quot;, &quot;LFS payroll&quot;, &quot;LFS payroll employment&quot;,
  6. &quot;LFS payroll average hours worked&quot;, &quot;LFS payroll average hourly earnings&quot;,
  7. &quot;SEPH payroll&quot;, &quot;SEPH payroll employment&quot;, &quot;SEPH payroll average hours worked&quot;,
  8. &quot;SEPH payroll average hourly earnings&quot;, &quot;LFS payroll&quot;, &quot;LFS payroll employment&quot;,
  9. &quot;LFS payroll average hours worked&quot;, &quot;LFS payroll average hourly earnings&quot;,
  10. &quot;SEPH payroll&quot;, &quot;SEPH payroll employment&quot;, &quot;SEPH payroll average hours worked&quot;,
  11. &quot;SEPH payroll average hourly earnings&quot;), V1 = c(65.4, 61.5, 6,
  12. 5.6, 8.9, 5.8, 0.3, 2.7, 9.2, 6.8, -0.3, 2.3, 0.8, 0.3, 0.1,
  13. 0.4, 1.3, 0.6, 0.6, 0.1), V2 = c(65, 60.8, 6.5, 5.4, 7.7, 5.8,
  14. -0.6, 2.3, 9.3, 7.8, -0.6, 2, -0.2, -1.5, 0.4, 0.9, 0.9, 0.1,
  15. 0, 0.9), V3 = c(65.4, 61.8, 5.5, 5.3, 9.5, 6.3, 0, 3.1, 10.1,
  16. 8, -0.6, 2.5, 1.9, 2.3, -0.3, -0.1, 0.8, 0.7, 0, 0), V4 = c(65.4,
  17. 61.9, 5.3, 5.7, 9.1, 5.1, 0.3, 3.5, 11.8, 7.2, -0.6, 4.9, 0.7,
  18. 0.3, 0.1, 0.3, 2.2, 0.8, -0.3, 1.7), V5 = c(65.3, 61.9, 5.2,
  19. 5.7, 9.3, 6.3, -0.5, 3.3, 10.2, 7, -1.2, 4.3, -0.2, 0, -0.6,
  20. 0.4, 0.2, 0.7, 0, -0.4), V6 = c(65.3, 61.9, 5.1, 5.7, 10.9, 7.2,
  21. -0.6, 3.9, 11.5, 8.6, -0.9, 3.5, 1.2, 0.2, 0.2, 0.8, -0.4, 0,
  22. -0.3, -0.3), V7 = c(64.9, 61.7, 4.9, 5.6, 11.3, 5.2, 0.6, 5.2,
  23. 11.2, 7.8, -0.6, 3.9, 1.3, 0.1, 0.5, 0.7, 1, 0.8, 0, 0.4), V8 = c(64.7,
  24. 61.6, 4.9, 5.5, 10.5, 4.2, 0.9, 5.2, 9, 5.9, -0.6, 3.3, 0, -0.4,
  25. -0.1, 0.4, 0.1, 0.1, 0, -0.1), V9 = c(64.8, 61.3, 5.4, 5.3, 9.4,
  26. 3.5, 0.3, 5.4, 9.2, 5.5, 0, 3.6, 0.2, -0.1, -0.4, 0.6, 0.8, 0,
  27. 0, 0.9), V10 = c(64.7, 61.3, 5.2, 5.2, 8.5, 2.6, 0.6, 5.2, 9.1,
  28. 5.5, -0.6, 3.8, 0.5, 0.2, 0.3, 0, 0.8, 0.5, -0.3, 0.4), V11 = c(64.9,
  29. 61.6, 5.2, 4.9, 8.8, 2.8, 0.3, 5.5, 7.9, 4.7, -1.2, 4.1, 1.1,
  30. 0.5, -0.1, 0.7, -0.6, 0, -0.6, 0.1), V12 = c(64.8, 61.5, 5.1,
  31. NA, 8.3, 2, 0.5, 5.6, NA, NA, NA, NA, 0.7, 0, 0.3, 0.5, NA, NA,
  32. NA, NA), V13 = c(65, 61.8, 5, NA, 7.7, 2.1, 0.3, 5.2, NA, NA,
  33. NA, NA, 0.2, 0.4, -0.1, 0, NA, NA, NA, NA)), row.names = c(NA,
  34. -20L), class = &quot;data.frame&quot;)
  35. LASTdate &lt;-&quot;2022-12-01&quot;
  36. NumMths &lt;- 12
  37. Dates &lt;- seq.Date(as.Date(&quot;2021-12-01&quot;),as.Date(&quot;2022-12-01&quot;),by=&quot;month&quot;)
  38. colls &lt;- c(&quot;V1&quot;,&quot;V2&quot;,&quot;V3&quot;,&quot;V4&quot;,&quot;V5&quot;,&quot;V6&quot;,&quot;V7&quot;,&quot;V8&quot;,&quot;V9&quot;,&quot;V10&quot;,&quot;V11&quot;,&quot;V12&quot;,&quot;V13&quot;)
  39. MyTitle &lt;- paste0(&quot;**Labour market indicators&lt;br&gt;&quot;,format(Dates[1],&quot;%B %Y&quot;),
  40. &quot; to &quot;,format(Dates[13],&quot;%B %Y&quot;),&quot;**&quot;)
  41. gt_tbl1 &lt;- gt(data=FdfT)
  42. gt_tbl1 &lt;- gt_tbl1 %&gt;%
  43. tab_options(table.font.size=12,container.width = 1450) %&gt;%
  44. tab_header(
  45. title=md(html(MyTitle))
  46. ) %&gt;%
  47. cols_align(
  48. align=c(&quot;left&quot;),
  49. columns=c(`Name`)
  50. ) %&gt;%
  51. fmt_number(
  52. columns=all_of(colls),
  53. decimals=1,
  54. use_seps=TRUE
  55. ) %&gt;%
  56. cols_label(
  57. `Name`=&quot;&quot;,
  58. `V1`=md(&quot;**Dec&lt;br&gt;2021**&quot;),
  59. `V2`=md(&quot;**Jan&lt;br&gt;2022**&quot;),
  60. `V3`=md(&quot;**Feb&lt;br&gt;2022**&quot;),
  61. `V4`=md(&quot;**Mar&lt;br&gt;2022**&quot;),
  62. `V5`=md(&quot;**Apr&lt;br&gt;2022**&quot;),
  63. `V6`=md(&quot;**May&lt;br&gt;2022**&quot;),
  64. `V7`=md(&quot;**Jun&lt;br&gt;2022**&quot;),
  65. `V8`=md(&quot;**Jul&lt;br&gt;2022**&quot;),
  66. `V9`=md(&quot;**Aug&lt;br&gt;2022**&quot;),
  67. `V10`=md(&quot;**Sep&lt;br&gt;2022**&quot;),
  68. `V11`=md(&quot;**Oct&lt;br&gt;2022**&quot;),
  69. `V12`=md(&quot;**Nov&lt;br&gt;2022**&quot;),
  70. `V13`=md(&quot;**Dec&lt;br&gt;2022**&quot;)
  71. ) %&gt;%
  72. sub_missing(columns=everything(),rows=everything(),
  73. missing_text=&quot;---&quot;) %&gt;%
  74. tab_style(
  75. style = list(
  76. cell_text(weight = &quot;bold&quot;)
  77. ),
  78. locations = cells_title()
  79. ) %&gt;%
  80. tab_style( # column label style
  81. style = list(
  82. cell_text(weight = &quot;bold&quot;)
  83. ),
  84. locations = cells_column_labels(
  85. columns=c(Name,all_of(colls)))
  86. ) %&gt;%
  87. tab_row_group(label=&quot;Ratio, per cent&quot;,
  88. rows=c(1:4),id=&quot;Levels&quot;) %&gt;%
  89. tab_row_group(label=&quot;12-month percentage change, per cent&quot;,
  90. rows=c(5:12),id=&quot;PC12&quot;) %&gt;%
  91. tab_row_group(label=&quot;1-month percentage change, per cent&quot;,
  92. rows=c(13:20),id=&quot;PC01&quot;) %&gt;%
  93. opt_row_striping(row_striping = TRUE) %&gt;%
  94. opt_vertical_padding(scale = 0.25) %&gt;%
  95. tab_footnote(
  96. footnote = paste0(&quot;Dashes mean &#39;data not yet available&#39;. Source for &quot;,
  97. &quot;data: Statistics Canada. @PhilSmith26. Prepared: &quot;,Sys.time()),
  98. locations = cells_title()
  99. )
  100. gt_tbl1
  101. ```
  1. </details>
  2. # 答案1
  3. **得分**: 4
  4. 我发现**必须升级到 quarto 的预发布版本 1.3**。接着以下的 YAML 代码会完成任务。
  5. ```yaml
  6. format:
  7. html:
  8. grid:
  9. sidebar-width: 0px
  10. body-width: 2000px
  11. margin-width: 0px
  12. gutter-width: 1.5rem
英文:

I discovered that one must update to the pre-release 1.3 of quarto. Then the following YAML code does the job.

  1. format:
  2. html:
  3. grid:
  4. sidebar-width: 0px
  5. body-width: 2000px
  6. margin-width: 0px
  7. gutter-width: 1.5rem

huangapple
  • 本文由 发表于 2023年1月9日 04:33:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051079.html
匿名

发表评论

匿名网友

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

确定