Skip to contents

Sets a wordmark or a logo behind the table body, faint enough to read through.

Usage

gt_watermark(
  gt_object,
  text = NULL,
  image = NULL,
  opacity = 0.06,
  size = "60%",
  position = "center",
  color = "#000000",
  angle = 0,
  font = "Helvetica, Arial, sans-serif"
)

Arguments

gt_object

A gt table object to modify.

text

Optional. Text to render as the watermark. Defaults to NULL.

image

Optional. A path to a PNG, JPEG, or SVG file to use instead of text. Defaults to NULL.

opacity

Numeric. How faint the watermark is, from 0 to 1. Defaults to 0.06.

size

Character. The width of the watermark relative to the table, as a CSS background size such as "60%". Defaults to "60%".

position

Character. Where it sits, as a CSS background position such as "center" or "right bottom". Defaults to "center".

color

Character. The text color, used only with text. Defaults to "#000000".

angle

Numeric. Rotation in degrees, used only with text. Defaults to 0.

font

Character. The font family for text. Defaults to a system sans-serif.

Value

Returns a modified gt table with a watermark behind the body.

Details

A text watermark is drawn as an inline SVG rather than as HTML, because a background image is the only way to sit behind the table body without taking up a row. An SVG background cannot load the page's webfonts, so font has to name a face installed on the machine rendering the table.

The watermark sits behind the body cells, so it will be hidden wherever a cell has its own fill, from row striping or from gt::data_color().

See also

gt_social_tag() for visible attribution in the source note.

Examples

library(gt)

gt(head(mtcars)) %>% gt_watermark(text = "DRAFT", angle = -30, opacity = 0.08)
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
# any local png, jpeg, gif or svg; a small svg written on the spot here logo <- tempfile(fileext = ".svg") writeLines(paste0( '<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40">', '<circle cx="20" cy="20" r="18"/></svg>' ), logo) gt(head(mtcars)) %>% gt_watermark(image = logo, size = "40%", position = "right bottom")
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1