0

I would like to import a .tex file into my RMarkdown document. I am using bookdown and importantly need to export to Word via word_document2. Is it possible to do this? Here is the way I would do this using LaTeX:

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

If there is a way to retain the LaTeX code, that would be ideal (because I am transferring everything over).

And here is a skeleton version of filename.tex

\begin{tabular}[t]{llc} \toprule AA & BB & CC\\ \midrule a & b & c\\ \bottomrule \end{tabular} 
5
  • 2
    Unrelated to the question, but instead of scaling content which contains text, better choose an appropriate font size, this will give a better typographical result. Commented Oct 15, 2021 at 19:01
  • Good point. Thank you, @samcarter_is_at_topanswers.xyz. Commented Oct 15, 2021 at 21:14
  • 1
    you can run tex code from anywhere inside the rmd by adding \input{filename.tex} (filename.tex can not inclue \usepackage (use header-includes) nor \begin{documen}) . This only works with pdf output to my knowledge. Commented Oct 20, 2021 at 0:03
  • Could you share the filename.tex file or at least a part of it? That would make it easier to test a few things. Commented Oct 21, 2021 at 13:16
  • Great suggestion, @JBGruber. I have updated the question. Commented Oct 21, 2021 at 14:50

1 Answer 1

2
+100

I tried solving this problem using pandoc. You can see an example from this question.

But as it was written in another question:

This does not work for more complicated tables.


I asked some of my friends: "What would you do in this situation?"

One of them told me about this tool to convert LaTeX tables to Markdown tables. It works nicely without tricky and big tables.

Converting

Let's have a look at your table in LaTeX.

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

The tool will convert the table into Markdown.

--- title: "test" output: word_document: default --- | AA | BB | CC | |:---:|:---:|:---:| | a | b | c | 

And it looks like this in Microsoft Word.

Word Document


This is all that I wanted to say. If it is not suitable for you or somebody couldn't solve this problem as expected – another option could be to try some R table packages like gt, flextable, kableExtra, or other packages of your choice.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.