2

I'm using knitr to rewrite some documents originally written in latex. Here is the preamble of the knitr

---
title: "Blabla"
date: "May 2, 2017"
bibliography: allpapers.bib
output:
  word_document:
    fig_caption: true
    reference_docx: "Empty.docx"
---

Now, in the original latex version I was using this:

\newcommand{\myinput}[1]{%
  \begingroup%
  \renewcommand\normalsize{\small}% Specify your font modification
  \input{#1}%
  \endgroup%
}
\begin{centering}
\myinput{table1.txt}
\end{centering}

The table1.txt is a prefomated latex table. I would like to include these tables in the ``knitrdocument without rewriting them from scratch, by just includingtable1.txtin theknitr`, somehow. How can this be done?

PS the table1.txt files have the form:

\begin{table}[ht]
\centering
\begin{tabular}{rllr}
  \hline
 & sdsd & dfdf & sdsd \\ 
  \hline
1 & sdsd & sdsd & -1.04 \\ 

   \hline
\end{tabular}
\caption{blabl.} 
\label{table1}
\end{table}
4

You can include LaTeX code verbatim in RMarkdown source files, and when you output to a format that uses LaTeX (i.e., pdf), the LaTeX is treated exactly as you expect.

However, if you're exporting to a non-LaTeX format, such as a word doc or html, then the exporter will just ignore the LaTeX.

---
title: "Test"
---

This is a test. Here's some \LaTeX{}:

\newcommand{\myinput}[1]{%
  \begingroup%
  \renewcommand\normalsize{\small}% Specify your font modification
  \input{#1}%
  \endgroup%
}
\begin{centering}
\myinput{table1.txt}
\end{centering}

Now I'm done.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.