kableExtra: вертикальное выравнивание не работает при выводе PDF со многими столбцами - PullRequest
0 голосов
/ 18 февраля 2020

Я хотел бы выровнять все столбцы в таблице kableExtra по верху. Параметр valign = "top", похоже, не решает проблему здесь. Кроме того, третий столбец почему-то опущен поверх второго по какой-то причине, и цитаты тоже не работают.

Приведенный ниже MWE основан на этом связанном вопросе SO, для которого нужны только 2 столбца: kable: вертикальное выравнивание не работает с выводом PDF

Снимок экрана MWE см. здесь: https://i.stack.imgur.com/RYg4r.jpg

   library(knitr)
   library(dplyr)
   library(kableExtra)

   num_obs <- 3
   text_string <- "Lorem ipsum dolor sit amet, vitae, augue aliquam luctus class non. Lectus maecenas ullamcorper commodo ut non maximus eros ad. Mollis rutrum bibendum ut ipsum nisl, mattis placerat, odio. Eu, non morbi nunc mollis." 
   fig_path <- paste0("\\includegraphics[scale=0.5]{uw.png} \\\\")
   fig_paths <- rep(fig_path, num_obs)

   table <- dplyr::tibble(
     col1 = 1:num_obs, 
     col2 = fig_paths,
     col3 = LETTERS[1:num_obs],
     col4 = c("\\href{http://eng.wikipedia.org}{Wiki}", "\\cite{R-base}", "\\cite{R-base}"),
     col5 = c(rep(text_string, num_obs))
   )

   kable(
     table, 
     escape = FALSE, # needed to be able to include latex commands
     format = "latex",  # format = latex, html
     booktabs = T, 
     align = "l",
     valign = "top", ## not working really
   ) %>% 
     kable_styling(full_width = F,
                   font_size = 9,
                   latex_options = c("hold_position")
     ) %>% 
     # row characteristics: set header row bold
     row_spec(row = 0, bold = T) %>%
     # column characteristics: set widths
     column_spec(1, width = "2em") %>% #
     column_spec(2, width = "6em") %>%
     column_spec(3, width = "3em") %>%
     column_spec(4, width = "20em") %>%
     column_spec(5, width = "10em") %>%
     # group rows together and give these groups labels
     pack_rows("Group 1", 1, 1) %>% 
     pack_rows("Group 2", 2, 3)
   ```
...