【问题标题】:How to import .tex file using RMarkdown and bookdown and word_document2如何使用 RMarkdown 和 bookdown 以及 word_document2 导入 .tex 文件
【发布时间】:2021-12-03 20:49:50
【问题描述】:

我想将一个 .tex 文件导入到我的 RMarkdown 文档中。我正在使用 bookdown,重要的是需要通过word_document2 导出到 Word。是否有可能做到这一点?这是我使用 LaTeX 的方法:

\begin{table}[H]
\caption{Table Title}
\label{usnwr_id}
\centering
\scalebox{0.8}{
\input{\dir/filename.tex}}
\caption*{\footnotesize \emph{Notes: ...}}
\end{table}

如果有办法保留 LaTeX 代码,那将是理想的(因为我正在转移所有内容)。

这里是 filename.tex 的骨架版本

\begin{tabular}[t]{llc}
\toprule
AA & BB & CC\\
\midrule
a & b & c\\
\bottomrule
\end{tabular}

【问题讨论】:

  • 与问题无关,但与其缩放包含文本的内容,不如选择合适的字体大小,这样会产生更好的排版效果。
  • 好点。谢谢你,@samcarter_is_at_topanswers.xyz。
  • 您可以通过添加 \input{filename.tex} (filename.tex 不能包括 \usepackage (use header-includes) 或 \begin{documen}) 从 rmd 内的任何位置运行 tex 代码。据我所知,这仅适用于 pdf 输出。
  • 您能分享 filename.tex 文件或至少其中的一部分吗?这样可以更轻松地测试一些东西。
  • 很好的建议,@JBGruber。我已经更新了问题。

标签: r ms-word latex r-markdown bookdown


【解决方案1】:

我尝试使用pandoc 解决这个问题。您可以从this question 看到一个示例。

但正如它所写的in another question

这不适用于更复杂的表格。


我问我的一些朋友:“在这种情况下你会怎么做?”

其中一位告诉我this tool 将 LaTeX 表格转换为 Markdown 表格。没有棘手的大桌子,它也能很好地工作。

转换

让我们看看你在 LaTeX 中的表格。

\begin{tabular}[t]{llc}
\toprule
AA & BB & CC\\
\midrule
a & b & c\\
\bottomrule
\end{tabular}

该工具会将表格转换为 Markdown。

---
title: "test"
output:  
  word_document: default
---

| AA | BB | CC |
|:---:|:---:|:---:|
| a  | b  | c  |

它在 Microsoft Word 中看起来像这样。


这就是我想说的。如果它不适合您或有人无法按预期解决此问题 - 另一种选择可能是尝试一些 R 表包,如 gtflextablekableExtra 或您选择的其他包。

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 2020-03-14
    相关资源
    最近更新 更多