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

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

Making quarto html documents use the full window width

问题

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

---
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
---

```{r set-options, echo=FALSE, warning=FALSE, cache=FALSE}
library(lubridate)
library(gt)
FdfT <- structure(list(Name = c("LFS participation rate", "LFS employment rate",
"LFS unemployment rate", "Job vacancy rate", "LFS payroll", "LFS payroll employment",
"LFS payroll average hours worked", "LFS payroll average hourly earnings",
"SEPH payroll", "SEPH payroll employment", "SEPH payroll average hours worked",
"SEPH payroll average hourly earnings", "LFS payroll", "LFS payroll employment",
"LFS payroll average hours worked", "LFS payroll average hourly earnings",
"SEPH payroll", "SEPH payroll employment", "SEPH payroll average hours worked",
"SEPH payroll average hourly earnings"), V1 = c(65.4, 61.5, 6,
5.6, 8.9, 5.8, 0.3, 2.7, 9.2, 6.8, -0.3, 2.3, 0.8, 0.3, 0.1,
0.4, 1.3, 0.6, 0.6, 0.1), V2 = c(65, 60.8, 6.5, 5.4, 7.7, 5.8,
-0.6, 2.3, 9.3, 7.8, -0.6, 2, -0.2, -1.5, 0.4, 0.9, 0.9, 0.1,
0, 0.9), V3 = c(65.4, 61.8, 5.5, 5.3, 9.5, 6.3, 0, 3.1, 10.1,
8, -0.6, 2.5, 1.9, 2.3, -0.3, -0.1, 0.8, 0.7, 0, 0), V4 = c(65.4,
61.9, 5.3, 5.7, 9.1, 5.1, 0.3, 3.5, 11.8, 7.2, -0.6, 4.9, 0.7,
0.3, 0.1, 0.3, 2.2, 0.8, -0.3, 1.7), V5 = c(65.3, 61.9, 5.2,
5.7, 9.3, 6.3, -0.5, 3.3, 10.2, 7, -1.2, 4.3, -0.2, 0, -0.6,
0.4, 0.2, 0.7, 0, -0.4), V6 = c(65.3, 61.9, 5.1, 5.7, 10.9, 7.2,
-0.6, 3.9, 11.5, 8.6, -0.9, 3.5, 1.2, 0.2, 0.2, 0.8, -0.4, 0,
-0.3, -0.3), V7 = c(64.9, 61.7, 4.9, 5.6, 11.3, 5.2, 0.6, 5.2,
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,
61.6, 4.9, 5.5, 10.5, 4.2, 0.9, 5.2, 9, 5.9, -0.6, 3.3, 0, -0.4,
-0.1, 0.4, 0.1, 0.1, 0, -0.1), V9 = c(64.8, 61.3, 5.4, 5.3, 9.4,
3.5, 0.3, 5.4, 9.2, 5.5, 0, 3.6, 0.2, -0.1, -0.4, 0.6, 0.8, 0,
0, 0.9), V10 = c(64.7, 61.3, 5.2, 5.2, 8.5, 2.6, 0.6, 5.2, 9.1,
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,
61.6, 5.2, 4.9, 8.8, 2.8, 0.3, 5.5, 7.9, 4.7, -1.2, 4.1, 1.1,
0.5, -0.1, 0.7, -0.6, 0, -0.6, 0.1), V12 = c(64.8, 61.5, 5.1,
NA, 8.3, 2, 0.5, 5.6, NA, NA, NA, NA, 0.7, 0, 0.3, 0.5, NA, NA,
NA, NA), V13 = c(65, 61.8, 5, NA, 7.7, 2.

<details>
<summary>英文:</summary>

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---

```{r set-options, echo=FALSE, warning=FALSE, cache=FALSE}
library(lubridate)
library(gt)
FdfT &lt;- structure(list(Name = c(&quot;LFS participation rate&quot;, &quot;LFS employment rate&quot;, 
&quot;LFS unemployment rate&quot;, &quot;Job vacancy rate&quot;, &quot;LFS payroll&quot;, &quot;LFS payroll employment&quot;, 
&quot;LFS payroll average hours worked&quot;, &quot;LFS payroll average hourly earnings&quot;, 
&quot;SEPH payroll&quot;, &quot;SEPH payroll employment&quot;, &quot;SEPH payroll average hours worked&quot;, 
&quot;SEPH payroll average hourly earnings&quot;, &quot;LFS payroll&quot;, &quot;LFS payroll employment&quot;, 
&quot;LFS payroll average hours worked&quot;, &quot;LFS payroll average hourly earnings&quot;, 
&quot;SEPH payroll&quot;, &quot;SEPH payroll employment&quot;, &quot;SEPH payroll average hours worked&quot;, 
&quot;SEPH payroll average hourly earnings&quot;), V1 = c(65.4, 61.5, 6, 
5.6, 8.9, 5.8, 0.3, 2.7, 9.2, 6.8, -0.3, 2.3, 0.8, 0.3, 0.1, 
0.4, 1.3, 0.6, 0.6, 0.1), V2 = c(65, 60.8, 6.5, 5.4, 7.7, 5.8, 
-0.6, 2.3, 9.3, 7.8, -0.6, 2, -0.2, -1.5, 0.4, 0.9, 0.9, 0.1, 
0, 0.9), V3 = c(65.4, 61.8, 5.5, 5.3, 9.5, 6.3, 0, 3.1, 10.1, 
8, -0.6, 2.5, 1.9, 2.3, -0.3, -0.1, 0.8, 0.7, 0, 0), V4 = c(65.4, 
61.9, 5.3, 5.7, 9.1, 5.1, 0.3, 3.5, 11.8, 7.2, -0.6, 4.9, 0.7, 
0.3, 0.1, 0.3, 2.2, 0.8, -0.3, 1.7), V5 = c(65.3, 61.9, 5.2, 
5.7, 9.3, 6.3, -0.5, 3.3, 10.2, 7, -1.2, 4.3, -0.2, 0, -0.6, 
0.4, 0.2, 0.7, 0, -0.4), V6 = c(65.3, 61.9, 5.1, 5.7, 10.9, 7.2, 
-0.6, 3.9, 11.5, 8.6, -0.9, 3.5, 1.2, 0.2, 0.2, 0.8, -0.4, 0, 
-0.3, -0.3), V7 = c(64.9, 61.7, 4.9, 5.6, 11.3, 5.2, 0.6, 5.2, 
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, 
61.6, 4.9, 5.5, 10.5, 4.2, 0.9, 5.2, 9, 5.9, -0.6, 3.3, 0, -0.4, 
-0.1, 0.4, 0.1, 0.1, 0, -0.1), V9 = c(64.8, 61.3, 5.4, 5.3, 9.4, 
3.5, 0.3, 5.4, 9.2, 5.5, 0, 3.6, 0.2, -0.1, -0.4, 0.6, 0.8, 0, 
0, 0.9), V10 = c(64.7, 61.3, 5.2, 5.2, 8.5, 2.6, 0.6, 5.2, 9.1, 
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, 
61.6, 5.2, 4.9, 8.8, 2.8, 0.3, 5.5, 7.9, 4.7, -1.2, 4.1, 1.1, 
0.5, -0.1, 0.7, -0.6, 0, -0.6, 0.1), V12 = c(64.8, 61.5, 5.1, 
NA, 8.3, 2, 0.5, 5.6, NA, NA, NA, NA, 0.7, 0, 0.3, 0.5, NA, NA, 
NA, NA), V13 = c(65, 61.8, 5, NA, 7.7, 2.1, 0.3, 5.2, NA, NA, 
NA, NA, 0.2, 0.4, -0.1, 0, NA, NA, NA, NA)), row.names = c(NA, 
-20L), class = &quot;data.frame&quot;)
LASTdate &lt;-&quot;2022-12-01&quot; 
NumMths &lt;- 12
Dates &lt;- seq.Date(as.Date(&quot;2021-12-01&quot;),as.Date(&quot;2022-12-01&quot;),by=&quot;month&quot;)
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;)
MyTitle &lt;- paste0(&quot;**Labour market indicators&lt;br&gt;&quot;,format(Dates[1],&quot;%B %Y&quot;),
&quot; to &quot;,format(Dates[13],&quot;%B %Y&quot;),&quot;**&quot;)
gt_tbl1 &lt;- gt(data=FdfT)
gt_tbl1 &lt;- gt_tbl1 %&gt;% 
tab_options(table.font.size=12,container.width = 1450) %&gt;%
tab_header(
title=md(html(MyTitle))
) %&gt;% 
cols_align(
align=c(&quot;left&quot;),
columns=c(`Name`)
) %&gt;%
fmt_number(
columns=all_of(colls),
decimals=1,
use_seps=TRUE
) %&gt;%
cols_label(
`Name`=&quot;&quot;,
`V1`=md(&quot;**Dec&lt;br&gt;2021**&quot;),
`V2`=md(&quot;**Jan&lt;br&gt;2022**&quot;),
`V3`=md(&quot;**Feb&lt;br&gt;2022**&quot;),
`V4`=md(&quot;**Mar&lt;br&gt;2022**&quot;),
`V5`=md(&quot;**Apr&lt;br&gt;2022**&quot;),
`V6`=md(&quot;**May&lt;br&gt;2022**&quot;),
`V7`=md(&quot;**Jun&lt;br&gt;2022**&quot;),
`V8`=md(&quot;**Jul&lt;br&gt;2022**&quot;),
`V9`=md(&quot;**Aug&lt;br&gt;2022**&quot;),
`V10`=md(&quot;**Sep&lt;br&gt;2022**&quot;),
`V11`=md(&quot;**Oct&lt;br&gt;2022**&quot;),
`V12`=md(&quot;**Nov&lt;br&gt;2022**&quot;),
`V13`=md(&quot;**Dec&lt;br&gt;2022**&quot;)
) %&gt;%
sub_missing(columns=everything(),rows=everything(),
missing_text=&quot;---&quot;) %&gt;%
tab_style(
style = list(
cell_text(weight = &quot;bold&quot;)
),
locations = cells_title()
) %&gt;%
tab_style( # column label style
style = list(
cell_text(weight = &quot;bold&quot;)
),
locations = cells_column_labels(
columns=c(Name,all_of(colls)))
) %&gt;%
tab_row_group(label=&quot;Ratio, per cent&quot;,
rows=c(1:4),id=&quot;Levels&quot;) %&gt;%
tab_row_group(label=&quot;12-month percentage change, per cent&quot;,
rows=c(5:12),id=&quot;PC12&quot;) %&gt;%
tab_row_group(label=&quot;1-month percentage change, per cent&quot;,
rows=c(13:20),id=&quot;PC01&quot;) %&gt;%
opt_row_striping(row_striping = TRUE) %&gt;%
opt_vertical_padding(scale = 0.25) %&gt;%
tab_footnote(
footnote = paste0(&quot;Dashes mean &#39;data not yet available&#39;. Source for &quot;,
&quot;data: Statistics Canada. @PhilSmith26.    Prepared: &quot;,Sys.time()),
locations = cells_title()
)
gt_tbl1
```

</details>
# 答案1
**得分**: 4
我发现**必须升级到 quarto 的预发布版本 1.3**。接着以下的 YAML 代码会完成任务。
```yaml
format:
html: 
grid:
sidebar-width: 0px
body-width: 2000px
margin-width: 0px
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.

format:
html: 
grid:
sidebar-width: 0px
body-width: 2000px
margin-width: 0px
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:

确定