我已经看到了在RMarkdown-HTML中创建并排xtable的答案
knitr, R Markdown, and xtable: xtable tables within HTML table

以及如何直接在Sweave中创建并排xtable
R: Print two tables with xtable ()

但是在Rmarkdown / Pandoc中并排xtables呢?

在我的* Rmd文件中

```{r , results='asis', message=FALSE, echo=FALSE}
female.bmi <- lm(bmi ~ AGEGROUP + RACE + GEO_SPA + FPL_FIN + as.factor(year),
              data=lach[lach$GENDER=='Female',] )
xtable(female.bmi, comment=FALSE, caption = 'Linear regression of BMI for females')
male.bmi <- lm(bmi ~ AGEGROUP + RACE + GEO_SPA + FPL_FIN + as.factor(year),
            data=lach[lach$GENDER=='Male',] )
xtable(male.bmi, comment=FALSE, caption = 'Linear regression of BMI for males')
```


然后我编译如下:

knit('Modeling/simple.rmd', 'Modeling/simple.md') # creates md file
pandoc('Modeling/simple.md', format='latex') # LaTeX/PDF


这些显示为单独的表格-很好!但是如何使它们显示为并排子图/子表?我试图将{r}print(xtable)代码周围的Latex子图代码进行集成,但无济于事。

最佳答案

好的,使用R markdown生成它很容易。以下是我的代码和结果:

我结合了您链接到的示例:

这是.Rmd文件的代码:

---
title: " 2 tables in markdown side by side"
author: "Marcin Kosiński"
date: "2014"
output:
   pdf_document:
      includes:
         in_header: header2.tex
      highlight: pygments
      toc: true
      toc_depth: 3
      number_sections: true
---

```{r,echo=FALSE}
library(knitr)
opts_chunk$set(comment="", message=FALSE,tidy.opts=list(keep.blank.line=TRUE, width.cutoff=120),options(width=100), cache=TRUE,fig.align='center',fig.height=6, fig.width=10,fig.path='figure/beamer-',fig.show='hold',size='footnotesize', cache=TRUE)
```

```{r}
library(xtable)
data(tli)
attach(tli)
x <- tli
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=x)
print(xtable(fm1), file="ta.tex", floating=FALSE)
print(xtable(head(tli, n=5)), file="tb.tex", floating=FALSE)
```

\begin{table}[ht]
\centering
\subfloat[Table x(a)]{\label{tab:tab1a}\scalebox{.5}{\input{./ta}}}\quad
\subfloat[Table x(b)]{\label{tab:tab1b}\scalebox{.5}{\input{./tb}}}
\caption{Caption about here}
\label{tab:tab1}
\end{table}


这是header2.tex文件的代码,需要与.Rmd文件位于同一文件夹中:

\usepackage{subfig}
\usepackage{graphicx}

关于r - 在Rmarkdown中并排Xtables,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23926671/

10-13 06:13