英文:
Converting Table to LaTeX and calling inline R Markdown
问题
我尝试在R Markdown中使用gtsummary,但它不直接支持。所以我将一个gtsummary
表格转换成了LaTeX格式并存储在变量latex_code
中。我的意图是内联调用它,但似乎不起作用。我的代码:
library(gt)
library(gtsummary)
# 过滤和未过滤数据集的表格比较。
comp <- mtcars %>% select(mpg, cyl, disp)
latex_code <- comp %>% tbl_summary(by = cyl) %>% as_gt() %>% as_latex()
latex_code %>% as.character() %>% cat()
r latex_code
我得到了以下错误:
! Argument of \@iiminipage has an extra }.
<inserted text>
\par
l.281 \end{table}
英文:
I'm trying to use gtsummary with R Markdown but it doesn't support it directly. So I took a gtsummary
table, converted it into LaTeX and stored it in a variable latex_code
. The intent was to call it inline but it doesn't seem to work. My code:
```{r}
library(gt)
library(gtsummary)
#Table comparison of filtered and unfiltered dataset.
comp <- mtcars %>% select(mpg, cyl, disp)
latex_code <- comp %>% tbl_summary(by = cyl) %>% as_gt() %>% as_latex()
latex_code %>% as.character() %>% cat()
```
`r latex_code`
I get the following error:
! Argument of \@iiminipage has an extra }.
<inserted text>
\par
l.281 \end{table}
答案1
得分: 1
gtsummary有大量的打印选项供R Markdown和Quarto使用(参见:https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html)。
根据您的设置(例如gt或flextable),已经选择了一些合理的打印引擎默认值,但您可以尝试该教程中列出的任何打印选项。
英文:
gtsummary has tons of printing options for R Markdown and Quarto (see: https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html).
Some sensible print engine defaults are chosen based on your setup (e.g. gt or flextable), but you can try any of the print options listed in that vignette for R Markdown.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论