# Getting R xtable to display within a LaTex 'minipage'

I have the following piece of R- / / minipage combo code.

What I am trying to do is get the xtable output to display within the minipage, along with other text paragraphs surrounding it. While my second xtable displays fine with markdown, the first one just repeats the code segment.

Any idea how I can get it to work?

---
output:
pdf_document: default
- \usepackage[dvipsnames]{xcolor}
- \usepackage{ragged2e}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \renewcommand{\footrulewidth}{0.4pt}
- \lfoot{blah blah}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---
\offinterlineskip
\fbox{\begin{minipage}[t]{46.5em}
\vspace*{0.3cm}\centering\textbf{METHODOLOGY}\vspace*{0.3cm}

\justify blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \vspace*{0.3cm}

\justify blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \vspace*{0.3cm}

<<echo=FALSE, results=tex>>=
library(xtable)
print(xtable(head(mtcars)), floating = FALSE, include.rownames = FALSE)
@
\end{minipage}}

\bigskip

**Table 1.** Blah blah blah Blah blah blah Blah blah blah Blah blah blah Blah

{r, xtable, results = 'asis', echo=FALSE, eval=TRUE, message=FALSE}
library(xtable)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)


• Check if results=tex is a valid option for markdown. Isn't it used with Sweave for making tables? results='asis' is correct, as you have already shown. – Ross Dec 22 '18 at 10:30

You cannot use result=tex option of Sweave in a R chunk in R markdown with uses the knitr syntax, but more important, you cannot use the R chunk syntax for noweb (.Rnw) files. Thas is, some like:

<<name,results='asis', option, option, ...>>=
2+2
@


Is still wrong, even if the chunk is inside the inside a LaTeX environment. Instead you must use always the R markdown syntax:

{r name, results='asis', option, option, ...}
2+2



In the MWE below there are many others changes in LaTeX, R and markdown irrelevants for the question, to simplify the example (removing headers,etc.) and the code (tcolorboxinstead of a minipage,etc.) or style suggestions (booktabsfor table rules,etc.}. The result:

---
- \usepackage[most]{tcolorbox}
- \usepackage{caption}
- \usepackage{parskip}
- \usepackage{booktabs}
output:
pdf_document: default
---

\begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=\bfseries\sffamily\centering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,

\subsection*{\centering METHODOLOGY}

Blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah.

Blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah.

\centering

{r table, echo=F,results="asis"}
library(xtable)

{r xtable, results = 'asis', echo=F}