blob: 8a060e52ac271c816bb8f50f8f6a384640b27d4c [file] [log] [blame]
Hao Zhue10cfd32017-02-21 16:41:14 -05001% Generated by roxygen2: do not edit by hand
Hao Zhuc1f38412017-02-23 12:13:48 -05002% Please edit documentation in R/kable_styling.R
3\name{kable_styling}
4\alias{kable_styling}
Hao Zhue10cfd32017-02-21 16:41:14 -05005\title{HTML table attributes}
6\usage{
Hao Zhua3fc0c42017-02-27 12:04:59 -05007kable_styling(kable_input, bootstrap_options = "basic",
Hao Zhu1fc48a62017-03-01 14:07:54 -05008 latex_options = "basic", full_width = NULL, position = "center",
Duncan Murdoch911dca32019-01-05 16:39:32 -05009 font_size = NULL, row_label_position = "l",
10 repeat_header_text = "\\\\textit{(continued)}",
11 repeat_header_method = c("append", "replace"),
12 repeat_header_continued = FALSE, stripe_color = "gray!6",
Hao Zhu9b051592019-01-07 18:13:51 -050013 stripe_index = NULL, latex_table_env = NULL, protect_latex = TRUE,
14 table.envir = "table")
Hao Zhue10cfd32017-02-21 16:41:14 -050015}
16\arguments{
Hao Zhu76281fe2017-07-03 19:33:09 -040017\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
Hao Zhuf7994dd2017-02-27 16:58:42 -050018
19\item{bootstrap_options}{A character vector for bootstrap table options.
Hao Zhu1fc48a62017-03-01 14:07:54 -050020Please see package vignette or visit the w3schools'
Hao Zhuf7994dd2017-02-27 16:58:42 -050021\href{https://www.w3schools.com/bootstrap/bootstrap_tables.asp}{Bootstrap Page}
Hao Zhu76281fe2017-07-03 19:33:09 -040022for more information. Possible options include \code{basic}, \code{striped},
23\code{bordered}, \code{hover}, \code{condensed} and \code{responsive}.}
Hao Zhuf7994dd2017-02-27 16:58:42 -050024
25\item{latex_options}{A character vector for LaTeX table options. Please see
Hao Zhu1fc48a62017-03-01 14:07:54 -050026package vignette for more information. Possible options include
Hao Zhu2a64dc62017-08-28 10:57:57 -040027\code{basic}, \code{striped}, \code{hold_position}, \code{HOLD_position}, \code{scale_down} & \code{repeat_header}.
Hao Zhu76281fe2017-07-03 19:33:09 -040028\code{striped} will add alternative row colors to the table. It will imports
29\code{LaTeX} package \code{xcolor} if enabled. \code{hold_position} will "hold" the floating
30table to the exact position. It is useful when the \code{LaTeX} table is contained
31in a \code{table} environment after you specified captions in \code{kable()}. It will
32force the table to stay in the position where it was created in the document.
Hao Zhu53e240f2017-09-04 20:04:29 -040033A stronger version: \code{HOLD_position} requires the \code{float} package and specifies \code{[H]}.
Hao Zhu76281fe2017-07-03 19:33:09 -040034\code{scale_down} is useful for super wide table. It will automatically adjust
35the table to page width. \code{repeat_header} in only meaningful in a longtable
Hao Zhu971d89f2017-06-07 19:22:47 -040036environment. It will let the header row repeat on every page in that long
37table.}
Hao Zhue10cfd32017-02-21 16:41:14 -050038
Hao Zhu76281fe2017-07-03 19:33:09 -040039\item{full_width}{A \code{TRUE} or \code{FALSE} variable controlling whether the HTML
Hao Zhuf7994dd2017-02-27 16:58:42 -050040table should have 100\% width. Since HTML and pdf have different flavors on
Hao Zhu76281fe2017-07-03 19:33:09 -040041the preferable format for \code{full_width}. If not specified, a HTML table will
42have full width by default but this option will be set to \code{FALSE} for a
Hao Zhuf7994dd2017-02-27 16:58:42 -050043LaTeX table}
Hao Zhu94956582017-02-21 18:18:29 -050044
Hao Zhuf7994dd2017-02-27 16:58:42 -050045\item{position}{A character string determining how to position the table
Hao Zhu76281fe2017-07-03 19:33:09 -040046on a page. Possible values include \code{left}, \code{center}, \code{right}, \code{float_left}
47and \code{float_right}. Please see the package doc site for demonstrations. For
48a \code{LaTeX} table, if \code{float_*} is selected, \code{LaTeX} package \code{wrapfig} will be
Hao Zhuf7994dd2017-02-27 16:58:42 -050049imported.}
Hao Zhu94956582017-02-21 18:18:29 -050050
51\item{font_size}{A numeric input for table font size}
Hao Zhua31e97f2017-06-08 14:55:41 -040052
Duncan Murdoch911dca32019-01-05 16:39:32 -050053\item{row_label_position}{A character string determining the justification
54of the row labels in a table. Possible values inclued \code{l} for left, \code{c} for
55center, and \code{r} for right. The default value is \code{l} for left justifcation.}
Hao Zhu68b5bbf2018-03-26 11:30:34 -040056
Duncan Murdoch911dca32019-01-05 16:39:32 -050057\item{repeat_header_text}{LaTeX option. A text string you want to append on
58or replace the caption.}
59
60\item{repeat_header_method}{LaTeX option, can either be \code{append}(default) or
61\code{replace}}
62
63\item{stripe_color}{LaTeX option allowing users to pick a different color
64for their strip lines. This option is not available in HTML}
65
Hao Zhud8516932019-01-06 18:56:47 -050066\item{stripe_index}{LaTeX option allowing users to customize which rows
67should have stripe color.}
68
Duncan Murdoch911dca32019-01-05 16:39:32 -050069\item{latex_table_env}{LaTeX option. A character string to define customized
70table environment such as tabu or tabularx.You shouldn't expect all features
71could be supported in self-defined environments.}
72
73\item{protect_latex}{If \code{TRUE}, LaTeX code embedded between dollar signs
Duncan Murdoch95c14372019-01-06 10:51:58 -050074will be protected from HTML escaping.}
Hao Zhu9b051592019-01-07 18:13:51 -050075
76\item{table.envir}{LaTeX floating table environment. \code{kable_style} will put
77a plain no-caption table in a \code{table} environment in order to center the
78table. You can specify this option to things like \code{table*} or \code{float*} based
79on your need.}
Hao Zhue10cfd32017-02-21 16:41:14 -050080}
81\description{
Hao Zhu26234122017-02-22 15:34:33 -050082This function provides a cleaner approach to modify the style
Hao Zhue7c8f702017-10-10 13:22:59 -040083of HTML tables other than using the \code{table.attr} option in \code{knitr::kable()}. Note
84that those bootstrap options requires Twitter bootstrap theme, which is not avaiable
85in some customized template being loaded.
Hao Zhue10cfd32017-02-21 16:41:14 -050086}
Hao Zhue1be9602017-08-17 15:44:31 -040087\details{
antaldanielcf11dac2018-05-30 21:54:37 +020088For LaTeX, if you use other than English environment
89\itemize{
90\item all tables are converted to 'UTF-8'. If you use, for example, Hungarian
91characters on a Windows machine, make sure to use
92Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.
Duncan Murdoch95c14372019-01-06 10:51:58 -050093\item \code{protect_latex = TRUE} has no effect.
94}
95
96For HTML,
97\itemize{
98\item \code{protect_latex = TRUE} is for including complicated math in HTML output.
99The LaTeX may not include dollar signs even if they are escaped.
100Pandoc's rules for recognizing embedded LaTeX are used.
antaldanielcf11dac2018-05-30 21:54:37 +0200101}
Hao Zhue1be9602017-08-17 15:44:31 -0400102}
Hao Zhu78e61222017-05-24 20:53:35 -0400103\examples{
104x_html <- knitr::kable(head(mtcars), "html")
105kable_styling(x_html, "striped", position = "left", font_size = 7)
106
107x_latex <- knitr::kable(head(mtcars), "latex")
108kable_styling(x_latex, latex_options = "striped", position = "float_left")
109
110}