Side by side Xtables in Rmarkdown

前端 未结 1 2073
半阙折子戏
半阙折子戏 2020-12-24 10:32

I have seen answers to creating side by side xtables in RMarkdown-HTML knitr, R Markdown, and xtable: xtable tables within HTML table

and how to create side by side

相关标签:
1条回答
  • 2020-12-24 10:43

    Ok it is very easy to produce it using R markdown. Below is my code and result:

    I combined the example you linked to:

    This is the code of .Rmd file:

    ---
    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}
    

    And here is a code of header2.tex file that need to be in the same folder as .Rmd file:

    \usepackage{subfig}
    \usepackage{graphicx}
    

    Result

    0 讨论(0)
提交回复
热议问题