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{ |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 7 | add_header_above( |
| 8 | kable_input, |
| 9 | header = NULL, |
| 10 | bold = FALSE, |
| 11 | italic = FALSE, |
| 12 | monospace = FALSE, |
| 13 | underline = FALSE, |
| 14 | strikeout = FALSE, |
| 15 | align = "c", |
| 16 | color = NULL, |
| 17 | background = NULL, |
| 18 | font_size = NULL, |
| 19 | angle = NULL, |
| 20 | escape = TRUE, |
| 21 | line = TRUE, |
| 22 | line_sep = 3, |
| 23 | extra_css = NULL, |
| 24 | include_empty = FALSE, |
| 25 | border_left = FALSE, |
| 26 | border_right = FALSE |
| 27 | ) |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 28 | } |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 29 | \arguments{ |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 30 | \item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified} |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 31 | |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 32 | \item{header}{A (named) character vector with \code{colspan} as values. For |
| 33 | example, \code{c(" " = 1, "title" = 2)} can be used to create a new header row |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 34 | for a 3-column table with "title" spanning across column 2 and 3. For |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 35 | convenience, when \code{colspan} equals to 1, users can drop the \verb{ = 1} part. |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 36 | As a result, \code{c(" ", "title" = 2)} is the same as \code{c(" " = 1, "title" = 2)}. |
| 37 | Alternatively, a data frame with two columns can be provided: The first |
| 38 | column should contain the header names (character vector) and the second |
| 39 | column should contain the colspan (numeric vector). This input can be used |
| 40 | if there are problems with unicode characters in the headers.} |
Hao Zhu | 32f43f7 | 2017-06-20 18:24:54 -0400 | [diff] [blame] | 41 | |
| 42 | \item{bold}{A T/F value to control whether the text should be bolded.} |
| 43 | |
| 44 | \item{italic}{A T/F value to control whether the text should to be emphasized.} |
Hao Zhu | ac7e70f | 2017-08-02 00:18:36 -0400 | [diff] [blame] | 45 | |
| 46 | \item{monospace}{A T/F value to control whether the text of the selected column |
| 47 | need to be monospaced (verbatim)} |
| 48 | |
Hao Zhu | 76f0eb6 | 2018-09-15 12:38:33 -0400 | [diff] [blame] | 49 | \item{underline}{A T/F value to control whether the text of the selected row |
| 50 | need to be underlined} |
| 51 | |
| 52 | \item{strikeout}{A T/F value to control whether the text of the selected row |
| 53 | need to be stricked out.} |
| 54 | |
Hao Zhu | 3465b50 | 2018-04-02 22:41:46 -0400 | [diff] [blame] | 55 | \item{align}{A character string for cell alignment. For HTML, possible values could |
| 56 | be \code{l}, \code{c}, \code{r} plus \code{left}, \code{center}, \code{right}, \code{justify}, \code{initial} and \code{inherit} |
| 57 | while for LaTeX, you can only choose from \code{l}, \code{c} & \code{r}.} |
| 58 | |
Hao Zhu | 76f0eb6 | 2018-09-15 12:38:33 -0400 | [diff] [blame] | 59 | \item{color}{A character string/vector for text color. Here please pay |
| 60 | attention to the differences in color codes between HTML and LaTeX.} |
| 61 | |
| 62 | \item{background}{A character string/vector for background color. Here please |
| 63 | pay attention to the differences in color codes between HTML and LaTeX. Also |
| 64 | note that in HTML, background defined in cell_spec won't cover the whole |
| 65 | cell.} |
| 66 | |
| 67 | \item{font_size}{A numeric input/vector for font size. For HTML, you can also use |
| 68 | options including \code{xx-small}, \code{x-small}, \code{small}, \code{medium}, \code{large}, |
| 69 | \code{x-large}, \code{xx-large}, \code{smaller}, \code{larger}, \code{initial} and \code{inherit}.} |
| 70 | |
| 71 | \item{angle}{0-360, degree that the text will rotate.} |
| 72 | |
Hao Zhu | ac7e70f | 2017-08-02 00:18:36 -0400 | [diff] [blame] | 73 | \item{escape}{A T/F value showing whether special characters should be |
| 74 | escaped.} |
Hao Zhu | 68b5bbf | 2018-03-26 11:30:34 -0400 | [diff] [blame] | 75 | |
| 76 | \item{line}{A T/F value to control whether a line will appear underneath the |
| 77 | header} |
Hao Zhu | 6d68f7c | 2018-09-15 12:44:15 -0400 | [diff] [blame] | 78 | |
Hao Zhu | b548aac | 2018-09-18 13:29:01 -0400 | [diff] [blame] | 79 | \item{line_sep}{A numeric value indicating how much the midlines should be |
| 80 | separated by space. Default is 3.} |
| 81 | |
Hao Zhu | 6d68f7c | 2018-09-15 12:44:15 -0400 | [diff] [blame] | 82 | \item{extra_css}{An HTML only option. CSS defined here will be send to the |
| 83 | td cell.} |
Hao Zhu | f64f475 | 2018-10-23 10:35:16 -0400 | [diff] [blame] | 84 | |
| 85 | \item{include_empty}{Whether empty cells in HTML should also be styled. |
| 86 | Default is FALSE.} |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 87 | |
| 88 | \item{border_left}{T/F option for border on the left side in latex.} |
| 89 | |
| 90 | \item{border_right}{T/F option for border on the right side in latex.} |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 91 | } |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 92 | \description{ |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 93 | Tables with multiple rows of header rows are extremely useful |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 94 | to demonstrate grouped data. This function takes the output of a \code{kable()} |
Hao Zhu | e7c8f70 | 2017-10-10 13:22:59 -0400 | [diff] [blame] | 95 | function and adds an header row on top of it. |
Hao Zhu | c1f3841 | 2017-02-23 12:13:48 -0500 | [diff] [blame] | 96 | } |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 97 | \examples{ |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame^] | 98 | \dontrun{ |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 99 | x <- knitr::kable(head(mtcars), "html") |
| 100 | # Add a row of header with 3 columns on the top of the table. The column |
| 101 | # span for the 2nd and 3rd one are 5 & 6. |
| 102 | add_header_above(x, c(" ", "Group 1" = 5, "Group 2" = 6)) |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame^] | 103 | } |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 104 | |
| 105 | } |