我正在用 R markdown 写一个文档,我想放一张桌子。问题是这张表只有两列,占了整整一页,不是很美观。所以我的问题是:有没有办法将这个表一分为二,并将两个“子表”并排放置,只有一个标题?
我使用 kable 命令并尝试了此解决方案(如何将 kable 拆分为多个列?)但我无法执行 cbind() 命令。
这是我创建表的代码:
---
title:
author:
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
indent: true
header-includes:
- \usepackage{indentfirst}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo = FALSE}
kable(aerop2, format = "markdown")
```
Run Code Online (Sandbox Code Playgroud)
其中 aerop2 是我的数据框,第 1 列是国家名称列表,第 2 列是这些国家/地区的机场数量。
我有一个很长的两列表,浪费空间。我想将此表拆分为两个子表,并将这些子表并排放置,并附上包含这两个子表的标题。
use*_*330 12
这并没有在间距上提供很大的灵活性,但这是一种方法。我使用mtcars数据集作为示例,因为我没有aerop2.
---
output: pdf_document
indent: true
header-includes:
- \usepackage{indentfirst}
- \usepackage{booktabs}
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
```
The data are in Table \ref{tab:tables}, which will float to the top of the page.
```{r echo = FALSE}
rows <- seq_len(nrow(mtcars) %/% 2)
kable(list(mtcars[rows,1:2],
matrix(numeric(), nrow=0, ncol=1),
mtcars[-rows, 1:2]),
caption = "This is the caption.",
label = "tables", format = "latex", booktabs = TRUE)
```
Run Code Online (Sandbox Code Playgroud)
这给出:
请注意,如果没有零行矩阵,两部分会更接近。要更多地增加间距,请将零行矩阵的额外副本放入列表中。
| 归档时间: |
|
| 查看次数: |
3497 次 |
| 最近记录: |