首页 > 解决方案 > r markdown longtable + Landscape kable标题宽度缩小(不再是页面宽度)

问题描述

我正在尝试将 longtable 和 lanscape 一起用于跨多个页面的宽表。当我这样做时,表格标题从页面的整个宽度变为页面中间的挤压。

我尝试使用以下建议无济于事。 R Markdown表格标题宽度与kable和longtable

我是 r markdown 的新手,而且我对 latek 一点也不熟悉,所以遵循上述说明让我感到困惑,尽管我已经尝试了所有我认为正确的选项。有人可以给我非常明确的分步说明,说明在 YAML 中的位置和内容以解决此问题吗?或者有人有其他工作吗?谢谢您的帮助

test <- data.frame(col1=rep("MyLongWordsareLong",5),
               col2=rep("MyLongWordsareLong",5),
               col3=rep("MyLongWordsareLong",5),
               col4=rep("MyLongWordsareLong",5),
               col5=rep("MyLongWordsareLong",5),
               col6=rep("MyLongWordsareLong",5))

kable(test,format='latex',booktabs=TRUE,
caption="This is my example caption. See how, when I don't use 
longtable, it extends the full width of the table, but when I use the 
longtable option, it compresses down to only a portion of the table's width. 
Is this weird or is it just me?") %>% 
 landscape()

kable(test,longtable=TRUE,format='latex',booktabs=TRUE,caption="This is my 
example caption. See how, when I don't use longtable, it extends the full 
width of the table, but when I use the longtable option, it compresses down 
to only a portion of the table's width. Is this weird or is it just me?") 
%>% 
landscape()

**编辑:我正在编织 PDF !

标签: latexr-markdownlandscapekablelongtable

解决方案


---
title: "Untitled"
author: "anonymous"
date: "14/12/2020"
header-includes:
  - \usepackage{caption}
output:
  pdf_document:
    keep_tex: yes
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(kableExtra)
```

```{r}
test <- data.frame(col1=rep("MyLongWordsareLong", 5),
               col2=rep("MyLongWordsareLong",5),
               col3=rep("MyLongWordsareLong",5),
               col4=rep("MyLongWordsareLong",5),
               col5=rep("MyLongWordsareLong",5),
               col6=rep("MyLongWordsareLong",5))

kable(test, booktabs=TRUE, caption="This is my example caption. See how, when I don't use  longtable, it extends the full width of the table, but when I use the longtable option, it compresses down to only a portion of the table's width.  Is this weird or is it just me?") %>% 
 landscape()

kable(test, longtable=TRUE, booktabs=TRUE, caption="This is my example caption. See how, when I don't use longtable, it extends the full  width of the table, but when I use the longtable option, it compresses down to only a portion of the table's width. Is this weird or is it just me?") %>% 
landscape()
```

根据R Markdown 表标题宽度与 kable 和 longtable 的解决方案


推荐阅读