flextable:仅将标题行对齐到中心。

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

flextable: align ONLY header row to center

问题

我有以下的代码,结果如下图所示。
然而,我希望 header_row 在列上居中对齐(作为参数传递的 colwidths,我一直在搜索,咨询手册(但我是 R 新手,所以我的理解很差),但我感到困惑。表中的其他所有内容都应该保持其原有的对齐方式。

ft <- flextable(df_BAS_sum)
ft <- set_caption(ft, caption = sprintf("Tabell 1. Arbetsmarknadsdata och nyckeltal för olika geografier, 20-64 år - %s %s", month, yr), align_with_table = FALSE)
ft <- add_header_row(ft, colwidths = c(1,2,4,3), values = c("","Arbetskraften","Ej i arbetskraften","Nyckeltal"))
ft <- colformat_num(x = ft,
                    big.mark = " ", decimal.mark = ",",
                    na_str = "N/A")
ft <- theme_vanilla(ft)
ft

flextable:仅将标题行对齐到中心。

感谢任何见解!

英文:

I have the following code which results in below fig.
However I want the header_row to align center over the cols.(passed as arg.:colwidths, I've been searching, consulted the manual (but I'm new to R so my understanding is bad), but I'm at a lost. Everything else in the table should have the alignment it has.

ft &lt;- flextable(df_BAS_sum)
ft &lt;- set_caption(ft, caption =sprintf(&quot;Tabell 1. Arbetsmarknadsdata och nyckeltal f&#246;r olika geografier, 20-64 &#229;r - %s %s&quot;, month, yr), align_with_table = F)
ft &lt;- add_header_row(ft, colwidths = c(1,2,4,3), values = c(&quot;&quot;,&quot;Arbetskraften&quot;,&quot;Ej i arbetskraften&quot;,&quot;Nyckeltal&quot;))
ft &lt;- colformat_num(x = ft,
                    big.mark=&quot; &quot;, decimal.mark = &quot;,&quot;,
                    na_str = &quot;N/A&quot;)
ft &lt;- theme_vanilla(ft)
ft

flextable:仅将标题行对齐到中心。

Thanks for any insight!

答案1

得分: 3

part = "header" 限定了它仅适用于标题行
i = 1(第一行)
j = NULL(所有列)应避免对其他标题行进行不必要的重新对齐。

英文:
ft &lt;- align(ft, i = 1, j = NULL, align = &quot;center&quot;, part = &quot;header&quot;)

part = &quot;header&quot; restricts it to the header rows only
i = 1 (first row)
j = NULL (all columns) should avoid the undesirable realignment of the other header row.

huangapple
  • 本文由 发表于 2023年3月1日 16:30:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601206.html
匿名

发表评论

匿名网友

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

确定