r - Rmarkdown 中并排 Xtable

标签 r latex markdown knitr

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

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

但是在 Rmarkdown/Pandoc 中并排 xtable 怎么样?

在我的 *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

这些显示为单独的表 - 很好!但是我怎样才能让它们显示为并排的子图/子表呢?我尝试将 Latex 子图代码集成到 {r}print(xtable) 代码周围,但无济于事。

最佳答案

好的,使用 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}

Result

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

相关文章:

latex - 减小条形图中 "nodes near coords"中的字体大小 #tikzpicture #pgfplots

node.js - 将原始 Markdown 文本传递给 Jade

markdown - 如何在 3-backticks 代码块中转义 3-backticks 代码块?

r - 如何计算依赖于使用每行变量值的函数的列?

r - 根据 R 中的标准获取之前的日期

r - 将 xtable 与 R 和 Latex 一起使用,列名中的数学模式?

用于解析 Latex 或 MathML 字符串的 Java 或 scala 库

r - R 中的卡方检验是否有成对事后比较?

r - 新名称 : * `` -> `..18` message in R console

intellij-idea - 如何在 IntelliJ IDEA 中插入 Markdown 表?