【问题标题】:Keep failing to generating a table in Rmarkdown beamer with the following error message一直无法在 Rmarkdown beamer 中生成表格,并显示以下错误消息
【发布时间】:2020-08-09 17:44:01
【问题描述】:

我正在尝试在 rmarkdown beamer (Rstudio) 中创建下表(附在下面)。它最初有效,但自从我更新了 R (3.6.3) 和 Rstudio 后,它就没有用了。我还更新了所有 pkg​​ 并重新安装了 tinytex pkg,但它不断生成以下错误消息:

output file: dp02_slide.knit.md

! File ended while scanning use of \beamer@collect@@body.
<inserted text> 
                \par 
<*> dp02_slide.tex

Error: LaTeX failed to compile dp02_slide.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See dp02_slide.log for more info.
Execution halted
---
title: "Big Business" 
output: 
  beamer_presentation:
      citation_package: natbib
      theme: "boxes"
header-includes:
- \widowpenalties 1 150
- \usepackage{amsmath}
- \renewcommand{\bibname}{References}
- \usepackage{adjustbox}
- \usepackage{booktabs}
- \usepackage{tikz}
- \usepackage{verbatim}
- \usepackage{chronosys}
- \usepackage{stackengine}
- \usepackage{xcolor}
- \usepackage{babel}
- \usetikzlibrary{arrows.meta}
- \usetikzlibrary{arrows,decorations.markings}
- \usetikzlibrary{intersections}
- \usepackage[font=small]{caption}
- \usepackage{adjustbox}
- \usepackage{tabularx}
- \usepackage{pgfplots}
- \pgfplotsset{compat=1.16}
- \usepackage[makeroom]{cancel}
- \renewcommand{\bibname}{References}
- \usepackage{subcaption}
- \usepackage{wrapfig}
---
# Table 1
\begin{table}[h!]
\centering
\small
\begin{adjustbox}{width=\columnwidth,center}
\begin{tabular}{ccccc}
\hline\hline
Stages & \textit{Financial regimes} & \textit{Preferential target} & \textit{Loan interest rates} & \begin{tabular}{@{}c@{}c@{}}\textit{Inequality} \\ \textit{trends} \\ \textit{(prediction)} \end{tabular} \\ [0.5ex]\hline
Stage I (1960s) &  \begin{tabular}{@{}c@{}c@{}}Repressed\\(Industry-neutral) \end{tabular} & Exporting firms & \begin{tabular}{@{}c@{}c@{}}Preferential rate ($r^{I}$)\\(based on \\export performance) \end{tabular}&$\searrow$?\\[1ex]\hline
\end{tabular}
\end{adjustbox}
\end{table}

图片:

【问题讨论】:

  • 你能不能发一个minimal reproducible example,我们可以复制+粘贴来重现你的问题?
  • 如果我在基本测试文档中使用你的代码片段,它编译得很好。
  • 我用相同问题的较短代码替换了它。我希望它有效。我还附上了我想作为链接生成的表格。谢谢@samcarter_is_at_topanswers.xyz
  • 不幸的是,您仍然只显示一个代码片段而不是一个可以让我们重现问题的小型测试文档。
  • 我认为这是您所期望的。否则,请告诉我。感谢您的耐心@samcarter

标签: r latex r-markdown beamer


【解决方案1】:

Rmarkdown 似乎无法处理方括号中的可选参数。作为一种解决方法,您可以将整个表格作为真正的乳胶代码。

关于您的代码的其他一些说明:

  • 您不需要\usepackage{amsmath} 和\usepackage{xcolor}。 Beamer 已经加载了它们

  • babel 包需要知道你想要哪种语言

  • 通常也不需要像 caption 这样的包,因为 beamer 有自己的字幕机制等。

  • 在没有浮动机制的文件类中使用像 [h!] 这样的浮动说明符是没有意义的

  • 您不需要在表格中出现\centering。 beamer 自动居中表格和图形

  • 我建议不要缩放包含文本的元素。与\begin{adjustbox}{width=\columnwidth,center}...\end{adjustbox} 相比,选择合适的字体大小会更好,以确保所使用的字母具有与其显示大小相匹配的最佳形状。


---
title: "Big Business" 
output: 
  beamer_presentation:
      citation_package: natbib
      theme: "boxes"
header-includes:
- \widowpenalties 1 150
- \usepackage{amsmath}
- \renewcommand{\bibname}{References}
- \usepackage{adjustbox}
- \usepackage{booktabs}
- \usepackage{tikz}
- \usepackage{verbatim}
- \usepackage{chronosys}
- \usepackage{stackengine}
- \usepackage{xcolor}
- \usetikzlibrary{arrows.meta}
- \usetikzlibrary{arrows,decorations.markings}
- \usetikzlibrary{intersections}
- \usepackage[font=small]{caption}
- \usepackage{adjustbox}
- \usepackage{tabularx}
- \usepackage{pgfplots}
- \renewcommand{\bibname}{References}
- \usepackage{subcaption}
- \usepackage{wrapfig}
---
# Table 1
```{=latex}
\begin{table}[h!]
\centering
\small
\begin{adjustbox}{width=\columnwidth,center}
\begin{tabular}{ccccc}
\hline\hline
Stages & \textit{Financial regimes} & \textit{Preferential target} & \textit{Loan interest rates} & \begin{tabular}{@{}c@{}c@{}}\textit{Inequality} \\ \textit{trends} \\ \textit{(prediction)} \end{tabular} \\ [0.5ex]\hline
Stage I (1960s) &  \begin{tabular}{@{}c@{}c@{}}Repressed\\(Industry-neutral) \end{tabular} & Exporting firms & \begin{tabular}{@{}c@{}c@{}}Preferential rate ($r^{I}$)\\(based on \\export performance) \end{tabular}&$\searrow$?\\[1ex]\hline
\end{tabular}
\end{adjustbox}
\end{table}
```

https://rstudio.cloud/project/1203195

【讨论】:

  • 这段代码似乎可以在您友好链接的环境中工作,但我的 rmarkdown 仍然会产生相同的错误消息:我在这里遗漏了什么吗? (我按照您的建议修改了代码)。 !扫描使用 \beamer@collect@@body 时文件结束。 \par dp02_slide.tex 错误:LaTeX 无法编译 dp02_slide.tex。有关调试提示,请参阅yihui.org/tinytex/r/#debugging。有关详细信息,请参阅 dp02_slide.log。执行停止
  • @joe 你能添加keep_tex: true 并显示生成的.tex 文件吗?
  • 我刚刚应您的要求添加了 tex 文件。事实上,这一次它会生成以下错误消息:文件在扫描使用 \beamer@collect@@body 时结束。 \par slide01.tex 错误:LaTeX 无法编译 slide01.tex。有关调试提示,请参阅yihui.org/tinytex/r/#debugging。有关详细信息,请参阅 slide01.log。执行停止
  • @joe mmm,不知何故,您的 rmarkdown 无法识别 ```{=latex} 块...
  • 当我删除以下在单元格中启用多行的代码时,它可以完美运行:\begin{tabular}{@{}c@{}c@{}}Repressed\(Industry-neutral) \结束{表格}。也许我应该寻找替代方法来完成这项工作?
猜你喜欢
  • 2018-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多