乳胶可折叠并排桌”;不是在外部PAR模式“>;

乳胶可折叠并排桌”;不是在外部PAR模式“>;,r,latex,knitr,kable,R,Latex,Knitr,Kable,我正在尝试创建一个包含并排表格的页面。我使用了其他答案来为一个简单的表做这件事 ```{r start-block, include=F,echo=F} library(dplyr) library(knitr) library(kableExtra) ``` ```{r sample, echo=FALSE, results='asis'} t1 <- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %>%

我正在尝试创建一个包含并排表格的页面。我使用了其他答案来为一个简单的表做这件事

```{r start-block, include=F,echo=F}
library(dplyr)
library(knitr)
library(kableExtra)
```

```{r sample, echo=FALSE, results='asis'}
t1 <- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5)
t2 <- kable(head(mtcars)[4:6], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5)
cat("\n")
cat("\\newpage")
cat("\\begin{table}[!htb]")
cat(c("\\begin{minipage}{.5\\linewidth}
       \\caption{}
       \\centering",
         t1,
     "\\end{minipage}%
     \\begin{minipage}{.5\\linewidth}
       \\centering
         \\caption{}",
         t2,
     "\\end{minipage}") )
cat("\\end{table}")
```

!胶乳错误:不在外PAR模式。< /强>

< P>我建议使用胶乳包来构建并列表/图。

示例.Rmd文件:

---
title: "Answer for SO Question 50879745"
header-includes:
  \usepackage{subcaption}
  \usepackage{booktabs}
  \usepackage[table]{xcolor}
---


```{r start-block}
library(dplyr)
library(knitr)
library(kableExtra)
opts_chunk$set(echo = FALSE)
``` 

Build two example tables based on the `mtcars` data set.


```{r sample, results='asis'}
t1 <- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5)
t2 <- kable(head(mtcars)[4:6], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5) 
```

Modify the tables to use the `subtable` environment and added labels and
captions.

```{r}
t1 <- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1a}This is Table 1 in the example, but now labeled with a (a).}\n", t1, fixed = TRUE)
t1 <- gsub("\\end{table}", "\\end{subtable}", t1, fixed = TRUE) 

t2 <- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1b}Shorter caption.}", t2, fixed = TRUE)
t2 <- gsub("\\end{table}", "\\end{subtable}", t2, fixed = TRUE) 
```

Place the tables into the document.

```{r, results = "asis"}
cat("",
    "\\begin{table}[!htb]",
    "\\centering",
    "\\caption{\\label{tab:tab1}Two tables, side-by-side.}",
    t1,
    t2,
    "\\end{table}",
    "",
    sep = "\n") 
```

Another example, start by reading in a rds file.


```{r table, results = "asis"}
tbl <- readRDS("table.RDS") #load file using the link "tbl"
cat(tbl)
```

A few modifications to Table~\ref{tab:comments-block} will be made so that we
can show the table twice in a `subtable`.

```{r table2_mod}
tbl <- gsub("\\begin{table}", "\\begin{subtable}[t]{0.48\\linewidth}", tbl, fixed = TRUE)
tbl <- gsub("\\end{table}", "\\end{subtable}", tbl, fixed = TRUE) 
```

Printing the tables works, see \ref{tab:tab3}, but there is overlap as the
tables are too wide.  Consider the `tabularx` package as a solution or an ad hoc
approach of changing the font size.

```{r, results = "asis"}
cat("",
    "\\begin{table}[!htb]",
    "\\centering",
    "\\caption{\\label{tab:tab3}Two tables, side-by-side.}",
    # "\\scriptsize",
    tbl,
    tbl,
    "\\end{table}",
    # "\\normalsize",
    "",
    sep = "\n") 
```
---
标题:“SO问题50879745的答案”
标题包括:
\usepackage{suboption}
\usepackage{booktabs}
\usepackage[表]{xcolor}
---
```{r开始块}
图书馆(dplyr)
图书馆(knitr)
图书馆(kableExtra)
选择块$set(echo=FALSE)
``` 
基于“mtcars”数据集构建两个示例表。
```{r sample,results='asis'}
t1%kable_样式(latex_选项=c(“条纹”),字体大小=5)
t2%可折叠样式(乳胶选项=c(“条纹”),字体大小=5)
```
修改表以使用“subtable”环境,并添加标签和
字幕。
```{r}

t1我通过添加
kable\u样式(latex\u options=c(“条纹”、“保持位置”))使表格并排显示。
。我查看了上面表t1的Latex,发现它以
\begin{table}[H]
开头,而我的表
tbl
没有[H]。kableExtra文档解释了如何添加hold参数,正如我在开头提到的。我不知道Latex,所以我不知道它为什么会起作用,但它确实起作用。将
-\usepackage{float}
-\floatplacement{table}{H}
添加到
头中包括:
YAML头的部分可能会起作用(基于本文),您的意思是
“保持位置”
。(这确实对我有用。)只有那个和
“保持位置”
```{r table2, echo=FALSE, results='asis'}
cat("\n")
cat("\\newpage")
cat("\\begin{table}[!htb]")
cat(c("\\begin{minipage}{.5\\linewidth}
       \\caption{}
       \\centering",
         tbl,
     "\\end{minipage}%
     \\begin{minipage}{.5\\linewidth}
       \\centering
         \\caption{}",
         tbl,
     "\\end{minipage}") )
cat("\\end{table}")
```
---
title: "Answer for SO Question 50879745"
header-includes:
  \usepackage{subcaption}
  \usepackage{booktabs}
  \usepackage[table]{xcolor}
---


```{r start-block}
library(dplyr)
library(knitr)
library(kableExtra)
opts_chunk$set(echo = FALSE)
``` 

Build two example tables based on the `mtcars` data set.


```{r sample, results='asis'}
t1 <- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5)
t2 <- kable(head(mtcars)[4:6], format = "latex", booktabs = TRUE) %>%  kable_styling(latex_options = c("striped"), font_size=5) 
```

Modify the tables to use the `subtable` environment and added labels and
captions.

```{r}
t1 <- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1a}This is Table 1 in the example, but now labeled with a (a).}\n", t1, fixed = TRUE)
t1 <- gsub("\\end{table}", "\\end{subtable}", t1, fixed = TRUE) 

t2 <- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1b}Shorter caption.}", t2, fixed = TRUE)
t2 <- gsub("\\end{table}", "\\end{subtable}", t2, fixed = TRUE) 
```

Place the tables into the document.

```{r, results = "asis"}
cat("",
    "\\begin{table}[!htb]",
    "\\centering",
    "\\caption{\\label{tab:tab1}Two tables, side-by-side.}",
    t1,
    t2,
    "\\end{table}",
    "",
    sep = "\n") 
```

Another example, start by reading in a rds file.


```{r table, results = "asis"}
tbl <- readRDS("table.RDS") #load file using the link "tbl"
cat(tbl)
```

A few modifications to Table~\ref{tab:comments-block} will be made so that we
can show the table twice in a `subtable`.

```{r table2_mod}
tbl <- gsub("\\begin{table}", "\\begin{subtable}[t]{0.48\\linewidth}", tbl, fixed = TRUE)
tbl <- gsub("\\end{table}", "\\end{subtable}", tbl, fixed = TRUE) 
```

Printing the tables works, see \ref{tab:tab3}, but there is overlap as the
tables are too wide.  Consider the `tabularx` package as a solution or an ad hoc
approach of changing the font size.

```{r, results = "asis"}
cat("",
    "\\begin{table}[!htb]",
    "\\centering",
    "\\caption{\\label{tab:tab3}Two tables, side-by-side.}",
    # "\\scriptsize",
    tbl,
    tbl,
    "\\end{table}",
    # "\\normalsize",
    "",
    sep = "\n") 
```