ฉันกำลังพยายามให้ R ระงับตารางที่มีความยาวที่สร้างด้วย kable & kableExtra ในเอาต์พุต Rmd แบบอินไลน์ในขณะที่เก็บไว้ใน PDF ที่ถักขั้นสุดท้าย ฉันต้องการทำสิ่งนี้เพียงไม่กี่ชิ้นเท่านั้น ดังนั้นฉันไม่ควรไปทางการตั้งค่าตัวเลือกส่วนกลางในการปิดเอาต์พุตอินไลน์ทั้งหมด
ฉันได้ทำซ้ำตัวเลือกอันต่างๆ ที่แสดงอยู่ที่นี่หลายครั้ง: https://yihui.name/knitr/demo/output/ และที่นี่: https://yihui.name/knitr/options/#plots แต่ยังไม่ได้ลงถูกจุด ดังนั้นฉันไม่แน่ใจว่าฉันดูถูกที่แล้วหรือว่าฉันเพิ่งข้ามการตั้งค่าที่ถูกต้องไป
YAML:
---
output:
pdf_document:
latex_engine: xelatex
---
รหัส:
```{r}
# Setup
library(knitr)
library(kableExtra)
# Create some data
dat <- data.frame ("A" = c(1:5),
"B" = c("Imagine a really long table",
"With at least 50 rows or so",
"Which get in the way in the inline output",
"But I want in the final PDF",
"Without influencing the other chunks")
)
# Produce the table
kable(dat, booktabs=TRUE, format="latex", longtable=TRUE) %>%
kable_styling(latex_options="HOLD_position")
```
เอาต์พุตอินไลน์ที่ฉันไม่ต้องการให้ปรากฏขึ้นทุกครั้งที่เรียกใช้สิ่งนี้:
\begin{table}[H]
\centering
\begin{tabular}{rl}
\toprule
A & B\\
\midrule
1 & Imagine a really long table\\
2 & With at least 50 rows or so\\
3 & Which get in the way in the inline output\\
4 & But I want in the final PDF\\
5 & Without influencing the other chunks\\
\bottomrule
\end{tabular}
\end{table}
หากคุณลองนึกภาพว่าต้องเลื่อนดูเนื้อหานี้ประมาณ 50-100 บรรทัดในขณะที่พยายามเขียนโค้ด คุณจะเห็นว่ามันน่ารำคาญและใช้เวลานานขนาดไหน