LaTex tables in R/Rmarkdown file

Hello,

I have this LaTex table from this link below:
I put it into either a R or Rmarkdown file.
It doesn't produce the result but gives squiggly red error lines that
I have to fix. How can I run the bottom LaTex code in R or Rmarkdown ?
Please advise !

LaTeX tables - Tutorial with code examples - LaTeX-Tutorial.com

%...

\begin{table}[h!]
\begin{center}
\caption{Multirow table.}
\label{tab:table1}
\begin{tabular}{l|S|r}
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\
\alpha & \beta & \gamma \
\hline
\multirow{2}{}{12} & 1110.1 & a\ % <-- Combining 2 rows with arbitrary with () and content 12
& 10.1 & b\ % <-- Content of first column omitted.
\hline
3 & 23.113231 & c\
4 & 25.113231 & d\
\end{tabular}
\end{center}
\end{table}

%...

Hey, what about this one?

---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage{caption}
- \usepackage{multirow}
---

some text

\begin{center}
\captionof{table}{Multirow Table.}
\begin{tabular}{l|l|r}
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3} \\
$\alpha$ & $\beta$ & $\gamma$ \\ \hline
\multirow{2}{*}{12} & 1110.1 & a \\
 & 10.1 & b \\ \hline
3 & 23.113231 & c \\
4 & 25.113231 & d
\end{tabular}
\end{center}

some text

This yields the following try.pdf (73.3 KB).

Edit based on following post

What exactly do you mean by this?

caption and multirow are LaTeX packages. If these are not installed on your device, tinytex will install them while knitting.

If you use some other TeX distribution, I think they can do that too. I used MikTeX earlier and it had an option to install packages on the fly.

I tried it on my computer it didn’t work.
Can’t put

\usepackage{caption}
\usepackage{multirow}

where you put them.
Please advise.

you may be right, those are LaTex package.
Let me get my Latex working and see if it works. Thx

Yarnabrina, I Installed MikTex however with your code is still not running it.
How can we run Latex code in R markdown.

Please advise

I don't want to assume anything, but I like to verify some things that may be overlooked when troubleshooting. No offense meant by these questions:

First, do you have the R Markdown package installed in your R environment? I assume since you are posting on the RStudio community forum, you do. In RStudio, go to your packages list, and check to make sure R Markdown is there.

Second, are you entering your code in an R Markdown document? An R Markdown document is created with an RMD extension. A normal R code file is created with an R extension. Under File, you chose New file, and then R Markdown document? Try that now to start a new file.

Third, paste Yarnabrina's code in to your new R Markdown document. Strictly speaking the hyphens before the \usepackage lines are not necessary. Now click the dropdown next to KNIT at the top of the window and choose Knit to PDF. Did it create the file with the table that you expected? On my system it did.

Some LaTeX packages work in all the various output formats for R Markdown and some don't. One of the packages that your example is using generates errors when using it in R Markdown to generate Word or HTML output but works fine when creating PDF.

Hope this helps

Yarnabrina and Edpflager,

Thank you for the advise.
I put the path for MikTex and it work.
It created the pdf document just as Yarnabrina had produced in his post.
However I can't produce html doc though.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.