使用R Markdown输出pdf。 kable()工作得很好但是当我添加longtable=T
时,标题不再扩展表的整个宽度。我似乎无法找到一个可以控制字幕细节的参数。我可以为每个代码块移动标题输出,但如果可能的话,我宁愿使用kable中的内置功能。</ p>
谢谢!
---
title: "test"
author: ""
date: "September 6, 2017"
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(kableExtra)
library(knitr)
library(dplyr)
```
```{r table1}
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 wdith.
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 wdith. Is this weird or is it just me?")
%>%
landscape()
```
答案 0 :(得分:2)
这可能是longtable
包中的LaTeX问题。此页面提供了一种解决方法:https://tex.stackexchange.com/questions/287283/how-to-define-caption-width-in-longtable。只需加上
header-includes:
- \usepackage{caption}
在您的YAML标题中,事情会按照您的预期运作。您还可以添加LaTeX代码
\captionsetup{width=5in}
(或使用其他一些指标,例如5cm
,\textwidth
,\textheight
等),以获得其他尺寸的一致字幕宽度。