Как уменьшить межстрочный интервал внутри вывода таблицы kable kableextra в pdf - PullRequest
0 голосов
/ 27 мая 2020

Я пытаюсь отформатировать неудобные таблицы, используя kable и kableextra (пишу bookdown). Есть ли способ уменьшить межстрочный интервал внутри таблицы (а не в теле документа)? То есть, интервал между строками текста, а не между строками с использованием \renewcommand{\arraystretch}{2}.

Мой лучший пример - это , но я не уверен, как заставить его работать в rmarkdown. Пока что у меня таблица выглядит примерно так:

ExampleTable

Настоящая таблица намного длиннее и выглядит неаккуратно.

Данные:


example_table <- structure(list(Book = structure(c(2L, 1L, 3L, 1L, 4L, 1L), .Label = c("", 
"1984", "Foundation", "The Hobbit"), class = "factor"), Author = structure(c(1L, 
2L, 1L, 3L, 1L, 4L), .Label = c("", "George Orwell", "Isaac Asimov", 
"Tolkien"), class = "factor"), Values = structure(c(4L, 2L, 4L, 
3L, 5L, 1L), .Label = c("0.8", "100", "4000", "Mean", "Min"), class = "factor"), 
    Values.1 = structure(c(5L, 2L, 5L, 3L, 4L, 1L), .Label = c("1", 
    "15", "500", "Max", "Standard deviation"), class = "factor"), 
    Values.2 = c(NA, NA, NA, NA, NA, NA), Example.long.text = structure(c(3L, 
    1L, 2L, 1L, 4L, 1L), .Label = c("", "born in the 11,988th year of the Galactic Era; died 12,069. The dates are more commonly given in terms of the current Foundational Era as -79 to the year 1 F.E. Born to middle-class parents on Helicon, Arcturus sector (where his father, in a legend of doubtful authenticity, was a tobacco grower in the hydroponic plants of the planet)...", 
    "It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him. ", 
    "Where did you go to, if I may ask? said Thorin to Gandalf as they rode along. To look ahead, said he. And what brought you back in the nick of time?  Looking behind,  said he."
    ), class = "factor")), class = "data.frame", row.names = c(NA, 
-6L))

Код таблицы:

\captionsetup{width=15cm}
```{r, ExampleTable, echo=FALSE,  message=FALSE, out.width='100%', fig.pos='H'}
library(kableExtra)

#example_table <- read.csv("ExampleTable.csv", fileEncoding = 'UTF-8-BOM')

knitr::kable(
  example_table,
  escape = FALSE, # Necessary for mathematical notation in table
  longtable = TRUE, # Necessary because real table is.... long
  booktabs = TRUE, # Necessary because background colours don't work if set to FALSE
#  linesep = "",
  caption = "A random reprex table that is a lot shorter than the real table with a bunch of random quotes.",
  col.names = c("Book",
                "Author",
                "Values",
                " ",
                " ",
                "Example long text")) %>%
  kable_styling(position = 'center', latex_options =c("HOLD_position"), font_size = 10) %>% 
  #add_indent(c(1, 9)) %>% 
  row_spec(c(1,2,5,6), background = "#f5f5f5") %>%
  column_spec(column = 1, width = "3cm") %>% 
  column_spec(column = c(4:5), width = "2cm") %>% 
  column_spec(column = 6, width = "9cm") %>% 
  landscape()

Дальнейшие вопросы форматирования, если вы знаете, следующие:

Можете ли вы определить, какая строка разбивается, когда longtable переходит на следующую страницу?

Может ли вывод PDF отображать цитаты (например, [@ orwel194]) так же, как HTML, без настройки format = 'markdown'?

Заранее спасибо!

...