为什么 kableExtra add_footnote() 导致 book down 编译失败?

Why is kableExtra add_footnote() causing book down compilation to fail?

我正在尝试为 https://github.com/proback/BeyondMLR 上的书制作 PDF

.Rmd 似乎都编译得很好, bookdown 吐出一个编织文件。具有 add_footnote() 步骤的表(如下所示)导致 bookdown 抛出错误。

这是 Rmd 文档中的 R 代码块:

Subject <- c(1,2,3,4,5,6)
`X (0 = home, 1 = work)` <- c(0,1,1,1,0,0)
`Y (number of cigarettes)` <- c(3,0,0,1,2,1)
ex3chp4 <- data.frame(Subject, `X (0 = home, 1 = work)`, 
                      `Y (number of cigarettes)`)
kable(ex3chp4, booktabs=T, 
      caption="A small subset of hypothetical data on Minnesota workplace rules on smoking.",
  col.names = c("Subject", "X (location)", "Y (cigarettes)")) %>%
kable_styling(full_width = F) %>%
add_footnote(c("X is 0 for home and 1 for work.", "Y is number of cigaretttes in a 2-hour period."), notation = "none")

add_footnote() 中,我得到以下内容:

! Misplaced \omit.
\multispan ->\omit 
                   \@multispan 
l.2035 ...cript{} X is 0 for home and 1 for work.}
                                                  \ 

我在之前的 table 中注释掉了 add_footnote(),没有出现错误。

如果我直接在控制台中 运行 上面的 R 代码,我会得到以下信息:

\begin{table}

\caption{A small subset of hypothetical data on Minnesota workplace rules on smoking.}
\centering
\begin{tabular}[t]{rrr}
\toprule{}
Subject & X (location) & Y (cigarettes)\
\midrule{}
1 & 0 & 3\
2 & 1 & 0\
3 & 1 & 0\
4 & 1 & 1\
5 & 0 & 2\
\addlinespace
6 & 0 & 1\
\bottomrule{}
\multicolumn{3}{l}{\textsuperscript{} X is 0 for home and 1 for work.}\
\multicolumn{3}{l}{\textsuperscript{} Y is number of cigaretttes in a 2-hour period.}\
\end{tabular}
\end{table}

对我来说,这看起来不错 LaTeX 输出……

如文档所述here,您只需安装 knitr 开发版:

remotes::install_github('yihui/knitr')