Reputation: 10966
I am using RStudio and writing an .Rnw file to include LATEX and R codes. There is a table to be inserted, and I use standard LATEX codes within the .Rnw file, like
\begin{table}[t]
\caption{SUMMARY}
\centering
\begin{tabular}{c|c|c|c|c|c}
\toprule
Data & stat1 & stat2 & stat3 & stat4 & stat5 \\
\midrule
itme1 & 36.101954 & 45 & 0.825500 & 0.220198 & 0.293448 \\
item2 & 51.828572 & 45 & 0.224900 & 0.499718 & 0.690064\\
item3 & 53.187455 & 45 & 0.188100 & 0.133086 & 0.603072 \\
item4 & 61.513952 & 45 & 0.051300 & 0.002566 & 0.014714 \\
\bottomrule
\end{tabular}
\label{tab:xxx}
\end{table}
However, when I click "Compile PDF" in RStudio, there is error message. I searched online about inserting tables in .Rnw file, and got the result of using xtable
package. Can I use standard LATEX codes for doing this? Thanks!
Upvotes: 2
Views: 2041
Reputation: 10966
The answer to "whether we can insert raw latex codes for making tables in the .Rnw file" is YES. I finally find out that the error comes from the underscore: if your column name include a _
, then you need to write \_
. Otherwise, when you click compile PDF in RStudio, there will be error messages produced (and it is extremely hard to debug!)
Upvotes: 2