r markdown longtable + chiều rộng của chú thích ngang kable co lại (không còn chiều rộng của trang)

Dec 14 2020

Tôi đang cố gắng sử dụng longtable và lanscape cùng nhau cho một bảng rộng kéo dài nhiều trang. Khi tôi làm điều này, chú thích bảng sẽ đi từ toàn bộ chiều rộng của trang xuống chỉ nằm gọn ở giữa trang.

Tôi đã thử sử dụng các đề xuất sau đây nhưng không có kết quả. R Chiều rộng chú thích bảng đánh dấu xuống với kable và longtable

Tôi mới làm quen với r markdown và tôi không quen thuộc với latek nên việc làm theo các hướng dẫn ở trên khiến tôi bối rối, mặc dù tôi đã thử tất cả các tùy chọn mà tôi cho là đúng. Ai đó có thể cung cấp cho tôi hướng dẫn từng bước rất rõ ràng về vị trí và những gì cần đưa vào YAML để khắc phục sự cố này không? Hoặc có ai có công việc khác xung quanh? Cảm ơn sự giúp đỡ của bạn

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()

** chỉnh sửa: Tôi đang đan thành PDF !!

Trả lời

1 Paul Dec 15 2020 at 06:11
---
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()
```

Giải pháp theo R Chiều rộng chú thích bảng Markdown với kable và longtable