LoginSignup
2
6

More than 5 years have passed since last update.

knitr to PDFでの複雑なテーブル(行グループのタイトルを追加する)

Last updated at Posted at 2018-01-06

Rstudio Cloudのリンクはこちらです。

rmakrdownとkableを使ってテーブルをかいてたところ、複雑なテーブルを書く際にkableExtraというパッケージがとても有用だということがわかったのでメモ。

library(knitr)
library(kableExtra)

#Motor Trend Car Road Tests in datasets package is loaded.
dt <- mtcars[1:5, 1:4]

# LaTeX Table
kable(dt, format = "latex", booktabs = T, caption = "Demo Table") %>%
  kable_styling(latex_options = c("striped", "hold_position"),
                full_width = F) %>%
  add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
  add_footnote(c("table footnote"))

Untitled.jpeg

ひとつの表の中に行グループのタイトルをつける。


  kable(dt, booktabs = T,
          format = "html", digits=2, #pdf出力の際はformat="latex"
        caption ="test table") %>% 
  kable_styling() %>%
  group_rows("group A", 1, 2) %>%
  group_rows("group B", 3, 3) %>% 
  group_rows("group C", 4, 5)

Untitled.jpeg

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6