# inline Latex in R markdown

I have a question about inline R Markdown code:

I have a finished LaTeX table that looks like this:

\begin{table}[!h]
\centering
\begin{tabular}{ |c|c|c|c|}
\hline
$\textbf{Vorname}$ &  $\textbf{Nachname}$ & $\textbf{Email}$ & $\textbf{Stimmen}$  \\
\midrule[1pt]
\specialrule{2pt}{-2pt}{-2pt}
\specialrule{2pt}{0pt}{0.5pt}
r Table[[2]][[1,1]] & r Table[[2]][[1,2]] & r Table[[2]][[1,3]] & r Table[[2]][[1,4]]\\ \hline
r Table[[2]][[2,1]] & r Table[[2]][[2,2]] & r Table[[2]][[2,3]] & r Table[[2]][[2,4]]\\ \hline
\end{tabular}
\end{table}

Here, I inserted some inline code (e.g. Table[[2]][[1,1]]) for the entries of the cell. Using the notation r [R code]. Now I would like to make this table dynamic: The amount of rows if supposed to be be given by a variable n.

So I want something of this kind:

\begin{table}
[LaTex code]
\specialrule{2pt}{0pt}{0.5pt}
j =0
for (j in 1:n){
r Table[[2]][[j,1]] & r Table[[2]][[j,2]] & r Table[[j]][[1,3]] & r Table[[2]][[j,4]] \\ \hline }
\end{tabular}

How can I achieve that?

• Without see R code generating a fake Tableobject and a whole rmarkdown file to test it, is hard to guess what you are trying, but anyway my advice is not make a LaTeX table with R chunks code in every cell, but construct first the table as a R dataframe (if Table is not already this) and then export the whole dataframe to LaTeX using xtable or kable. This last part could be as simple as library(xtable); xtable(yourdataframe). – Fran Apr 14 at 13:05
• ok thank you very much – stefanR Apr 14 at 21:48