Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/add_header_above.R |
| 3 | \name{add_header_above} |
| 4 | \alias{add_header_above} |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 5 | \title{Add a header row on top of current header} |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 6 | \usage{ |
| 7 | add_header_above(kable_input, header = NULL) |
| 8 | } |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 9 | \arguments{ |
| 10 | \item{kable_input}{Output of `knitr::kable()` with `format` specified} |
| 11 | |
| 12 | \item{header}{A (named) character vector with `colspan` as values. For |
| 13 | example, `c(" " = 1, "title" = 2)` can be used to create a new header row |
| 14 | for a 3-column table with "title" spanning across column 2 and 3. For |
| 15 | convenience, when `colspan` equals to 1, users can drop the ` = 1` part. |
| 16 | As a result, `c(" ", "title" = 2)` is the same as `c(" " = 1, "title" = 2)`.} |
| 17 | } |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 18 | \description{ |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 19 | Tables with multiple rows of header rows are extremely useful |
| 20 | to demonstrate grouped data. This function takes the output of a `kable()` |
| 21 | function and adds an header row on top of it. This function can work with |
| 22 | both `HTML` and `LaTeX` outputs |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 23 | } |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 24 | \examples{ |
| 25 | x <- knitr::kable(head(mtcars), "html") |
| 26 | # Add a row of header with 3 columns on the top of the table. The column |
| 27 | # span for the 2nd and 3rd one are 5 & 6. |
| 28 | add_header_above(x, c(" ", "Group 1" = 5, "Group 2" = 6)) |
| 29 | |
| 30 | } |