Getting R xtable to display within a LaTex 'minipage'
I have the following piece of R
-markdown / latex / 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
header-includes:
- usepackage[dvipsnames]{xcolor}
- usepackage{ragged2e}
- usepackage{fancyhdr}
- pagestyle{fancy}
- lhead{textsc{blah blah}}
- rhead{textsc{bfseries large blah blah}}
- renewcommand{footrulewidth}{0.4pt}
- lfoot{blah blah}
- fancypagestyle{plain}{pagestyle{fancy}}
---
fcolorbox{Fuchsia}{Fuchsia}{begin{minipage}{46.5em}centeringtextbf{largecolor{white}ABOUT THIS TEST}end{minipage}}
offinterlineskip
fbox{begin{minipage}[t]{46.5em}
vspace*{0.3cm}centeringtextbf{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)
x <- head(mtcars)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)
```
minipage r xtable fbox
This question had a bounty worth +50
reputation from Gopala that ended yesterday. Grace period has ended
This question has not received enough attention.
Still looking for a solution that works. I can't make it work with many things I tried.
add a comment |
I have the following piece of R
-markdown / latex / 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
header-includes:
- usepackage[dvipsnames]{xcolor}
- usepackage{ragged2e}
- usepackage{fancyhdr}
- pagestyle{fancy}
- lhead{textsc{blah blah}}
- rhead{textsc{bfseries large blah blah}}
- renewcommand{footrulewidth}{0.4pt}
- lfoot{blah blah}
- fancypagestyle{plain}{pagestyle{fancy}}
---
fcolorbox{Fuchsia}{Fuchsia}{begin{minipage}{46.5em}centeringtextbf{largecolor{white}ABOUT THIS TEST}end{minipage}}
offinterlineskip
fbox{begin{minipage}[t]{46.5em}
vspace*{0.3cm}centeringtextbf{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)
x <- head(mtcars)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)
```
minipage r xtable fbox
This question had a bounty worth +50
reputation from Gopala that ended yesterday. Grace period has ended
This question has not received enough attention.
Still looking for a solution that works. I can't make it work with many things I tried.
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
add a comment |
I have the following piece of R
-markdown / latex / 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
header-includes:
- usepackage[dvipsnames]{xcolor}
- usepackage{ragged2e}
- usepackage{fancyhdr}
- pagestyle{fancy}
- lhead{textsc{blah blah}}
- rhead{textsc{bfseries large blah blah}}
- renewcommand{footrulewidth}{0.4pt}
- lfoot{blah blah}
- fancypagestyle{plain}{pagestyle{fancy}}
---
fcolorbox{Fuchsia}{Fuchsia}{begin{minipage}{46.5em}centeringtextbf{largecolor{white}ABOUT THIS TEST}end{minipage}}
offinterlineskip
fbox{begin{minipage}[t]{46.5em}
vspace*{0.3cm}centeringtextbf{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)
x <- head(mtcars)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)
```
minipage r xtable fbox
I have the following piece of R
-markdown / latex / 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
header-includes:
- usepackage[dvipsnames]{xcolor}
- usepackage{ragged2e}
- usepackage{fancyhdr}
- pagestyle{fancy}
- lhead{textsc{blah blah}}
- rhead{textsc{bfseries large blah blah}}
- renewcommand{footrulewidth}{0.4pt}
- lfoot{blah blah}
- fancypagestyle{plain}{pagestyle{fancy}}
---
fcolorbox{Fuchsia}{Fuchsia}{begin{minipage}{46.5em}centeringtextbf{largecolor{white}ABOUT THIS TEST}end{minipage}}
offinterlineskip
fbox{begin{minipage}[t]{46.5em}
vspace*{0.3cm}centeringtextbf{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)
x <- head(mtcars)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)
```
minipage r xtable fbox
minipage r xtable fbox
asked Dec 22 '18 at 0:34
GopalaGopala
613
613
This question had a bounty worth +50
reputation from Gopala that ended yesterday. Grace period has ended
This question has not received enough attention.
Still looking for a solution that works. I can't make it work with many things I tried.
This question had a bounty worth +50
reputation from Gopala that ended yesterday. Grace period has ended
This question has not received enough attention.
Still looking for a solution that works. I can't make it work with many things I tried.
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
add a comment |
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
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
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
add a comment |
1 Answer
1
active
oldest
votes
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 (booktabs
for table rules,etc.}. The result:
---
header-includes:
- usepackage[most]{tcolorbox}
- usepackage{caption}
- usepackage{parskip}
- usepackage{booktabs}
output:
pdf_document: default
---
begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=bfseriessffamilycentering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]parskip1em
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
captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466928%2fgetting-r-xtable-to-display-within-a-latex-minipage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 (booktabs
for table rules,etc.}. The result:
---
header-includes:
- usepackage[most]{tcolorbox}
- usepackage{caption}
- usepackage{parskip}
- usepackage{booktabs}
output:
pdf_document: default
---
begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=bfseriessffamilycentering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]parskip1em
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
captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```
add a comment |
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 (booktabs
for table rules,etc.}. The result:
---
header-includes:
- usepackage[most]{tcolorbox}
- usepackage{caption}
- usepackage{parskip}
- usepackage{booktabs}
output:
pdf_document: default
---
begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=bfseriessffamilycentering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]parskip1em
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
captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```
add a comment |
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 (booktabs
for table rules,etc.}. The result:
---
header-includes:
- usepackage[most]{tcolorbox}
- usepackage{caption}
- usepackage{parskip}
- usepackage{booktabs}
output:
pdf_document: default
---
begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=bfseriessffamilycentering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]parskip1em
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
captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```
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 (booktabs
for table rules,etc.}. The result:
---
header-includes:
- usepackage[most]{tcolorbox}
- usepackage{caption}
- usepackage{parskip}
- usepackage{booktabs}
output:
pdf_document: default
---
begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=bfseriessffamilycentering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]parskip1em
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
captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```
answered Jan 8 at 2:18
FranFran
51.7k6114175
51.7k6114175
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466928%2fgetting-r-xtable-to-display-within-a-latex-minipage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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