blob: a3932fc432f900550251e4d5e2ea7df1d1036124 [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",
Duncan Murdoch95c14372019-01-06 10:51:58 -050013 latex_table_env = NULL, protect_latex = TRUE)
Hao Zhue10cfd32017-02-21 16:41:14 -050014}
15\arguments{
Hao Zhu76281fe2017-07-03 19:33:09 -040016\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
Hao Zhuf7994dd2017-02-27 16:58:42 -050017
18\item{bootstrap_options}{A character vector for bootstrap table options.
Hao Zhu1fc48a62017-03-01 14:07:54 -050019Please see package vignette or visit the w3schools'
Hao Zhuf7994dd2017-02-27 16:58:42 -050020\href{https://www.w3schools.com/bootstrap/bootstrap_tables.asp}{Bootstrap Page}
Hao Zhu76281fe2017-07-03 19:33:09 -040021for more information. Possible options include \code{basic}, \code{striped},
22\code{bordered}, \code{hover}, \code{condensed} and \code{responsive}.}
Hao Zhuf7994dd2017-02-27 16:58:42 -050023
24\item{latex_options}{A character vector for LaTeX table options. Please see
Hao Zhu1fc48a62017-03-01 14:07:54 -050025package vignette for more information. Possible options include
Hao Zhu2a64dc62017-08-28 10:57:57 -040026\code{basic}, \code{striped}, \code{hold_position}, \code{HOLD_position}, \code{scale_down} & \code{repeat_header}.
Hao Zhu76281fe2017-07-03 19:33:09 -040027\code{striped} will add alternative row colors to the table. It will imports
28\code{LaTeX} package \code{xcolor} if enabled. \code{hold_position} will "hold" the floating
29table to the exact position. It is useful when the \code{LaTeX} table is contained
30in a \code{table} environment after you specified captions in \code{kable()}. It will
31force the table to stay in the position where it was created in the document.
Hao Zhu53e240f2017-09-04 20:04:29 -040032A stronger version: \code{HOLD_position} requires the \code{float} package and specifies \code{[H]}.
Hao Zhu76281fe2017-07-03 19:33:09 -040033\code{scale_down} is useful for super wide table. It will automatically adjust
34the table to page width. \code{repeat_header} in only meaningful in a longtable
Hao Zhu971d89f2017-06-07 19:22:47 -040035environment. It will let the header row repeat on every page in that long
36table.}
Hao Zhue10cfd32017-02-21 16:41:14 -050037
Hao Zhu76281fe2017-07-03 19:33:09 -040038\item{full_width}{A \code{TRUE} or \code{FALSE} variable controlling whether the HTML
Hao Zhuf7994dd2017-02-27 16:58:42 -050039table should have 100\% width. Since HTML and pdf have different flavors on
Hao Zhu76281fe2017-07-03 19:33:09 -040040the preferable format for \code{full_width}. If not specified, a HTML table will
41have full width by default but this option will be set to \code{FALSE} for a
Hao Zhuf7994dd2017-02-27 16:58:42 -050042LaTeX table}
Hao Zhu94956582017-02-21 18:18:29 -050043
Hao Zhuf7994dd2017-02-27 16:58:42 -050044\item{position}{A character string determining how to position the table
Hao Zhu76281fe2017-07-03 19:33:09 -040045on a page. Possible values include \code{left}, \code{center}, \code{right}, \code{float_left}
46and \code{float_right}. Please see the package doc site for demonstrations. For
47a \code{LaTeX} table, if \code{float_*} is selected, \code{LaTeX} package \code{wrapfig} will be
Hao Zhuf7994dd2017-02-27 16:58:42 -050048imported.}
Hao Zhu94956582017-02-21 18:18:29 -050049
50\item{font_size}{A numeric input for table font size}
Hao Zhua31e97f2017-06-08 14:55:41 -040051
Duncan Murdoch911dca32019-01-05 16:39:32 -050052\item{row_label_position}{A character string determining the justification
53of the row labels in a table. Possible values inclued \code{l} for left, \code{c} for
54center, and \code{r} for right. The default value is \code{l} for left justifcation.}
Hao Zhu68b5bbf2018-03-26 11:30:34 -040055
Duncan Murdoch911dca32019-01-05 16:39:32 -050056\item{repeat_header_text}{LaTeX option. A text string you want to append on
57or replace the caption.}
58
59\item{repeat_header_method}{LaTeX option, can either be \code{append}(default) or
60\code{replace}}
61
62\item{stripe_color}{LaTeX option allowing users to pick a different color
63for their strip lines. This option is not available in HTML}
64
65\item{latex_table_env}{LaTeX option. A character string to define customized
66table environment such as tabu or tabularx.You shouldn't expect all features
67could be supported in self-defined environments.}
68
69\item{protect_latex}{If \code{TRUE}, LaTeX code embedded between dollar signs
Duncan Murdoch95c14372019-01-06 10:51:58 -050070will be protected from HTML escaping.}
Hao Zhue10cfd32017-02-21 16:41:14 -050071}
72\description{
Hao Zhu26234122017-02-22 15:34:33 -050073This function provides a cleaner approach to modify the style
Hao Zhue7c8f702017-10-10 13:22:59 -040074of HTML tables other than using the \code{table.attr} option in \code{knitr::kable()}. Note
75that those bootstrap options requires Twitter bootstrap theme, which is not avaiable
76in some customized template being loaded.
Hao Zhue10cfd32017-02-21 16:41:14 -050077}
Hao Zhue1be9602017-08-17 15:44:31 -040078\details{
antaldanielcf11dac2018-05-30 21:54:37 +020079For LaTeX, if you use other than English environment
80\itemize{
81\item all tables are converted to 'UTF-8'. If you use, for example, Hungarian
82characters on a Windows machine, make sure to use
83Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.
Duncan Murdoch95c14372019-01-06 10:51:58 -050084\item \code{protect_latex = TRUE} has no effect.
85}
86
87For HTML,
88\itemize{
89\item \code{protect_latex = TRUE} is for including complicated math in HTML output.
90The LaTeX may not include dollar signs even if they are escaped.
91Pandoc's rules for recognizing embedded LaTeX are used.
antaldanielcf11dac2018-05-30 21:54:37 +020092}
Hao Zhue1be9602017-08-17 15:44:31 -040093}
Hao Zhu78e61222017-05-24 20:53:35 -040094\examples{
95x_html <- knitr::kable(head(mtcars), "html")
96kable_styling(x_html, "striped", position = "left", font_size = 7)
97
98x_latex <- knitr::kable(head(mtcars), "latex")
99kable_styling(x_latex, latex_options = "striped", position = "float_left")
100
101}