(编辑于 2019 年 7 月 11 日以包含问题group_rows()
)
我正在 Markdown 文档中制作一个表格,其中将包含不同情况的方程式。当我在 Markdown 中编写数组时,它会这样:
当我使用 将相同的方程式包含在表中kable()
时,数组末尾的条件会被破坏:
有谁知道如何让 kableExtra 表中的条件看起来像在表外一样?我希望最后的条件是一致的。手动添加空格 ( 0\\\ \\\ \\\ \\\ \\\ a = 0 \\\\
) 看起来很糟糕。在继续使用更黑客的解决方案之前,我很想知道如何在 Markdown 中修复它。以下每种情况的代码。
Markdown 中的方程:
$$C_{y,a}=
\begin{cases}
0 & a=0 \\
\frac{C_y N_{y,a}}{N_y^{1+}} & a>0 \\
\end{cases}$$
Markdown 表格中的相同等式:
**Table 1.** Population dynamics.
```{r echo = F}
Equation_number <- c(1,2)
Equation <- c("$N_{i1,y} = R_{i,y} = R_{0,i }e^{\\tau_{i,y}}$",
"$C_{y,a}=
\\begin{cases}
0 & a=0 \\\\
\\frac{C_y N_{y,a}}{N_y^{1+}} & a>0 \\\\
\\end{cases}$")
Description <- c("Initial numbers at age","Catches at age")
Population_Equations <- data.frame(cbind(Equation_number,
Equation,
Description))
colnames(Population_Equations) = c("Eq.",
"Equation",
"Description")
knitr::kable(format="html",
Population_Equations,
escape = FALSE) %>%
kable_styling()
```
提前感谢您的任何指导!
***** 编辑 7/11/19:上述问题已针对常规情况修复,但在group_rows()
用于表格时发生:
knitr::kable(format="html",
Population_Equations,
escape = FALSE) %>%
group_rows(index=c("First group"=1, "Second group"=1)) %>%
kable_styling()
结果是:
会话信息:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.10 knitr_1.23 magrittr_1.5 usethis_1.5.1 devtools_2.1.0 pkgload_1.0.2
[8] R6_2.4.0 rlang_0.4.0 tools_3.6.1 pkgbuild_1.0.3 xfun_0.8 sessioninfo_1.1.1 cli_1.1.0
[15] withr_2.1.2 remotes_2.1.0 htmltools_0.3.6 yaml_2.2.0 assertthat_0.2.1 digest_0.6.20 rprojroot_1.3-2
[22] crayon_1.3.4 processx_3.4.0 callr_3.3.0 fs_1.3.1 ps_1.3.0 curl_3.3 rsconnect_0.8.13
[29] testthat_2.1.1 glue_1.3.1 memoise_1.1.0 evaluate_0.14 rmarkdown_1.13 compiler_3.6.1 desc_1.2.0
[36] backports_1.1.4 prettyunits_1.0.2