更新到 Quarto v1.6.4 现在会丢失 kableExtra 表

问题描述 投票:0回答:1

我有 v1.2 左右的四开本,我刚刚将其更新到 v1.6.4。

在更新之前,我有一个 PDF 文档,它在放置桌子方面没有给我带来任何困难。

我的最小工作示例在这里:

---
title: "kableExtra tables"
subtitle: "Not behaving as expected anymore"
format: 
  pdf: 
    fig-pos: H
    include-in-header:
      text: |
        \addtokomafont{disposition}{\rmfamily}

number-sections: true
execute: 
  echo: false
  
fig-cap-location: top

toc: false
---
```{=latex}
\vspace{-3.4cm}
\tableofcontents{}
```

```{r}
#| include: false
## Loading packages and data  
library(tidyverse)
library(kableExtra)
data <- mtcars %>%
  rownames_to_column(var="carnames")
```

## First section
```{r}
#| include: false
## Preparing the tables  
data1.1 <- data %>% head(4) %>% select(carnames, mpg)
data1.2 <- data %>% head(4) %>% select(cyl, hp)

tbl1.1 <- data1.1 %>%
  kbl(booktabs = T, digits = 2, format.args = list(big.mark = ".", decimal.mark = ","),
      linesep = "\\addlinespace") %>%
  kable_styling(latex_options = c("striped", "full_width"),
                position = "center") %>% 
  row_spec(nrow(data1.1), bold = T, hline_after = T) %>% 
  add_header_above(c(" " = 1, "test 1" = 1))

tbl1.2 <- data1.2 %>%
  kbl(booktabs = T, digits = 0, format.args = list(big.mark = ".", decimal.mark = ","),
      linesep = "\\addlinespace") %>%
  kable_styling(latex_options = c("striped", "full_width"),
                position = "center") %>% 
  row_spec(nrow(data1.2), bold = T, hline_after = T) %>% 
  add_header_above(c("test 2" = 1))
```

Tables next to each other.

```{r}
#| label: tbl-example1
#| tbl-cap: "A very exciting caption"
#| tbl-subcap: 
#|     - "mpg of certain cars."
#|     - "cylender sizes and horse power, I guess."
#| layout-ncol: 2
tbl1.1
tbl1.2
```

## Second section

```{r}
#| include: false
## Preparing the tables  
data2 <- data %>% head(15) %>% 
  bind_rows(summarise(.,
                    across(where(is.numeric), sum),
                    across(where(is.character), ~ "Total")))
```

```{r}
#| label: tbl-mtcars
#| tbl-cap: "Full view of mtcars data set." 
data2 %>% 
  kbl(booktabs = T, digits = 0, format.args = list(big.mark = ".", decimal.mark = ","),
      linesep = "\\addlinespace") %>%
  kable_styling(latex_options = c("striped", "full_width"),
                position = "center") %>% 
  row_spec(nrow(data2), bold = T, hline_after = T) %>% 
  add_header_above(c(" " = 1, "details" = 7, "interesting" = 4))
```

它给了我下面屏幕截图中的输出。

在更新之前,我还在

latex_options = c("striped", "full_width", "HOLD_position")
中指定了
kable_styling
。但是
"HOLD_position"
并没有对 v1.6.4 中的表格位置做任何事情(与屏幕截图中的位置相同),而是为每个表格添加了烦人的 [H]“标签”。因此我现在将其删除。它确实有助于在我之前使用过的早期版本的 Quarto 中进行定位。

现在它可以自由选择放置表格的位置,而不是遵循 .qmd 文件中的文本流。我尝试将

tbl-pos: H
放入 YAML 标头中来修复它,但这没有任何影响。

我可以单独或全局做什么(就像我对 YAML 标题中的数字所做的那样)将表格定位为遵循文本顺序?想要的输出是在文本“彼此相邻的表格”之后出现的两个表格,然后在第二节标题之后出现较大的表格。

enter image description here

pdf latex quarto kableextra
1个回答
0
投票

尝试添加另一行 LaTeX 以强制所有表格浮动对 YAML 元数据中的

include-in-header
键使用 HOLD:

include-in-header:
 text: |
   \addtokomafont{disposition}{\rmfamily}
   \floatplacement{table}{H}

KableExtra 和 Quarto 的集成遇到了一些麻烦,尤其是在 LaTeX 中。但这个解决方案对我来说帮助了这个特定问题

© www.soinside.com 2019 - 2024. All rights reserved.