# 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 ?

https://www.latex-tutorial.com/tutorials/tables/

%...

\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}

%...

---
title: "Untitled"
output: pdf_document
- \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).

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

\usepackage{caption}
\usepackage{multirow}

where you put them.

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.

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.

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

Is there any specific reason to use MikTeX? I think cderv advised you to use tinytex in a previous thread.

But that shouldn't matter. Let me add a few questions, assuming that your answer is yes to all but the third question of Edpflager:

1. Have you add MikTeX to the system path? [I mentioned the steps in that thread]
2. Have you installed the required LaTeX packages that I've included at the YAML section? That can be done from MikTeX Package Manager.

If you fail to use my code even after these, then I guess you'll have to let us know what are the exact problems you're facing. Please provide the exact error that you're getting. I'm not that familiar with LaTeX, and hence won't be able to help if it's too complicated, but it'll help others with more expertise to understand what's going on.

Good luck!

Yarnabrina and Edpflager,