blob: a7bc566d0d6311b1b34b35b55c23045dc6d3c786 [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 Zhu9410a272020-08-03 01:11:47 -04007kable_styling(
8 kable_input,
9 bootstrap_options = "basic",
10 latex_options = "basic",
11 full_width = NULL,
12 position = "center",
13 font_size = NULL,
14 row_label_position = "l",
Duncan Murdoch911dca32019-01-05 16:39:32 -050015 repeat_header_text = "\\\\textit{(continued)}",
16 repeat_header_method = c("append", "replace"),
Hao Zhu9410a272020-08-03 01:11:47 -040017 repeat_header_continued = FALSE,
18 stripe_color = "gray!6",
19 stripe_index = NULL,
20 latex_table_env = NULL,
21 protect_latex = TRUE,
22 table.envir = "table",
Hao Zhuad4ea392020-08-10 01:24:50 -040023 fixed_thead = FALSE,
Hao Zhu33b865f2020-08-18 02:10:43 -040024 htmltable_class = NULL,
Hao Zhuf2f42022020-08-18 22:48:52 -040025 html_font = NULL,
26 wraptable_width = "0pt"
Hao Zhu9410a272020-08-03 01:11:47 -040027)
Hao Zhue10cfd32017-02-21 16:41:14 -050028}
29\arguments{
Hao Zhu76281fe2017-07-03 19:33:09 -040030\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
Hao Zhuf7994dd2017-02-27 16:58:42 -050031
32\item{bootstrap_options}{A character vector for bootstrap table options.
Hao Zhu1fc48a62017-03-01 14:07:54 -050033Please see package vignette or visit the w3schools'
Hao Zhuf7994dd2017-02-27 16:58:42 -050034\href{https://www.w3schools.com/bootstrap/bootstrap_tables.asp}{Bootstrap Page}
Hao Zhu76281fe2017-07-03 19:33:09 -040035for more information. Possible options include \code{basic}, \code{striped},
Hao Zhuad4ea392020-08-10 01:24:50 -040036\code{bordered}, \code{hover}, \code{condensed}, \code{responsive} and \code{none}.}
Hao Zhuf7994dd2017-02-27 16:58:42 -050037
38\item{latex_options}{A character vector for LaTeX table options. Please see
Hao Zhu1fc48a62017-03-01 14:07:54 -050039package vignette for more information. Possible options include
Hao Zhu2a64dc62017-08-28 10:57:57 -040040\code{basic}, \code{striped}, \code{hold_position}, \code{HOLD_position}, \code{scale_down} & \code{repeat_header}.
Hao Zhu76281fe2017-07-03 19:33:09 -040041\code{striped} will add alternative row colors to the table. It will imports
42\code{LaTeX} package \code{xcolor} if enabled. \code{hold_position} will "hold" the floating
43table to the exact position. It is useful when the \code{LaTeX} table is contained
44in a \code{table} environment after you specified captions in \code{kable()}. It will
45force the table to stay in the position where it was created in the document.
Hao Zhu9410a272020-08-03 01:11:47 -040046A stronger version: \code{HOLD_position} requires the \code{float} package and specifies \verb{[H]}.
Hao Zhu76281fe2017-07-03 19:33:09 -040047\code{scale_down} is useful for super wide table. It will automatically adjust
48the table to page width. \code{repeat_header} in only meaningful in a longtable
Hao Zhu971d89f2017-06-07 19:22:47 -040049environment. It will let the header row repeat on every page in that long
50table.}
Hao Zhue10cfd32017-02-21 16:41:14 -050051
Hao Zhu76281fe2017-07-03 19:33:09 -040052\item{full_width}{A \code{TRUE} or \code{FALSE} variable controlling whether the HTML
Hao Zhu9410a272020-08-03 01:11:47 -040053table should have 100\\% width. Since HTML and pdf have different flavors on
Hao Zhu76281fe2017-07-03 19:33:09 -040054the preferable format for \code{full_width}. If not specified, a HTML table will
55have full width by default but this option will be set to \code{FALSE} for a
Hao Zhuf7994dd2017-02-27 16:58:42 -050056LaTeX table}
Hao Zhu94956582017-02-21 18:18:29 -050057
Hao Zhuf7994dd2017-02-27 16:58:42 -050058\item{position}{A character string determining how to position the table
Hao Zhu76281fe2017-07-03 19:33:09 -040059on a page. Possible values include \code{left}, \code{center}, \code{right}, \code{float_left}
60and \code{float_right}. Please see the package doc site for demonstrations. For
Hao Zhu9410a272020-08-03 01:11:47 -040061a \code{LaTeX} table, if \verb{float_*} is selected, \code{LaTeX} package \code{wrapfig} will be
Hao Zhuf7994dd2017-02-27 16:58:42 -050062imported.}
Hao Zhu94956582017-02-21 18:18:29 -050063
64\item{font_size}{A numeric input for table font size}
Hao Zhua31e97f2017-06-08 14:55:41 -040065
Duncan Murdoch911dca32019-01-05 16:39:32 -050066\item{row_label_position}{A character string determining the justification
67of the row labels in a table. Possible values inclued \code{l} for left, \code{c} for
68center, and \code{r} for right. The default value is \code{l} for left justifcation.}
Hao Zhu68b5bbf2018-03-26 11:30:34 -040069
Duncan Murdoch911dca32019-01-05 16:39:32 -050070\item{repeat_header_text}{LaTeX option. A text string you want to append on
71or replace the caption.}
72
73\item{repeat_header_method}{LaTeX option, can either be \code{append}(default) or
74\code{replace}}
75
Hao Zhu1c4917e2019-01-15 17:00:01 -060076\item{repeat_header_continued}{T/F or a text string. Whether or not to put
77a continued mark on the second page of longtable. If you put in text, we will
78use this text as the "continued" mark.}
79
Duncan Murdoch911dca32019-01-05 16:39:32 -050080\item{stripe_color}{LaTeX option allowing users to pick a different color
81for their strip lines. This option is not available in HTML}
82
Hao Zhud8516932019-01-06 18:56:47 -050083\item{stripe_index}{LaTeX option allowing users to customize which rows
84should have stripe color.}
85
Duncan Murdoch911dca32019-01-05 16:39:32 -050086\item{latex_table_env}{LaTeX option. A character string to define customized
87table environment such as tabu or tabularx.You shouldn't expect all features
88could be supported in self-defined environments.}
89
90\item{protect_latex}{If \code{TRUE}, LaTeX code embedded between dollar signs
Duncan Murdoch95c14372019-01-06 10:51:58 -050091will be protected from HTML escaping.}
Hao Zhu9b051592019-01-07 18:13:51 -050092
93\item{table.envir}{LaTeX floating table environment. \code{kable_style} will put
94a plain no-caption table in a \code{table} environment in order to center the
Hao Zhu9410a272020-08-03 01:11:47 -040095table. You can specify this option to things like \verb{table*} or \verb{float*} based
Hao Zhu9b051592019-01-07 18:13:51 -050096on your need.}
Hao Zhu72917f92019-03-15 18:41:42 -040097
98\item{fixed_thead}{HTML table option so table header row is fixed at top.
99Values can be either T/F or \code{list(enabled = T/F, background = "anycolor")}.}
Hao Zhuad4ea392020-08-10 01:24:50 -0400100
Hao Zhu3676fe22020-08-11 19:42:42 -0400101\item{htmltable_class}{Options to use the in-house lightable themes.
Hao Zhuad4ea392020-08-10 01:24:50 -0400102Choices include \code{lightable-minimal}, \code{lightable-classic},
Hao Zhu3676fe22020-08-11 19:42:42 -0400103\code{lightable-classic-2}, \code{lightable-material}, \code{lightable-striped} and
104\code{lightable-hover}. If you have your customized style sheet loaded which
105defines your own table class, you can also load it here.}
Hao Zhu33b865f2020-08-18 02:10:43 -0400106
107\item{html_font}{A string for HTML css font. For example,
108\code{html_font = '"Arial Narrow", arial, helvetica, sans-serif'}.}
Hao Zhuf2f42022020-08-18 22:48:52 -0400109
110\item{wraptable_width}{Width of the wraptable area if you specify
111"float_left/right" for latex table. Default is "0pt" for automated
112determination but you may specify it manually.}
Hao Zhue10cfd32017-02-21 16:41:14 -0500113}
114\description{
Hao Zhu26234122017-02-22 15:34:33 -0500115This function provides a cleaner approach to modify the style
Hao Zhue7c8f702017-10-10 13:22:59 -0400116of HTML tables other than using the \code{table.attr} option in \code{knitr::kable()}. Note
117that those bootstrap options requires Twitter bootstrap theme, which is not avaiable
118in some customized template being loaded.
Hao Zhue10cfd32017-02-21 16:41:14 -0500119}
Hao Zhue1be9602017-08-17 15:44:31 -0400120\details{
antaldanielcf11dac2018-05-30 21:54:37 +0200121For LaTeX, if you use other than English environment
122\itemize{
123\item all tables are converted to 'UTF-8'. If you use, for example, Hungarian
124characters on a Windows machine, make sure to use
125Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.
Duncan Murdoch95c14372019-01-06 10:51:58 -0500126\item \code{protect_latex = TRUE} has no effect.
127}
128
129For HTML,
130\itemize{
131\item \code{protect_latex = TRUE} is for including complicated math in HTML output.
132The LaTeX may not include dollar signs even if they are escaped.
133Pandoc's rules for recognizing embedded LaTeX are used.
antaldanielcf11dac2018-05-30 21:54:37 +0200134}
Hao Zhue1be9602017-08-17 15:44:31 -0400135}
Hao Zhu78e61222017-05-24 20:53:35 -0400136\examples{
Hao Zhu9399dcc2020-08-26 17:27:38 -0400137\dontrun{
Hao Zhu78e61222017-05-24 20:53:35 -0400138x_html <- knitr::kable(head(mtcars), "html")
139kable_styling(x_html, "striped", position = "left", font_size = 7)
140
141x_latex <- knitr::kable(head(mtcars), "latex")
142kable_styling(x_latex, latex_options = "striped", position = "float_left")
Hao Zhu9399dcc2020-08-26 17:27:38 -0400143}
Hao Zhu78e61222017-05-24 20:53:35 -0400144
145}