Skip to contents

This function adds a row of horizontal bars at the top of a gt table, using a character vector of hex color codes. The bars are added as a caption with customizable height, width, alignment, image size, text formatting, and image/text alignment. If image or text is provided, only one color will be used, and that bar will contain the image and/or text. The function automatically inherits the font from the gt object and uses the corresponding Google Font for any text rendered in the bar.

Usage

gt_border_bars_top(
  gt_object,
  colors,
  bar_height = 10,
  bar_width = "100%",
  bar_align = "center",
  img = NULL,
  img_width = 30,
  img_height = 30,
  img_padding = 10,
  img_align = "right",
  text = NULL,
  text_weight = "bold",
  text_color = "#FFFFFF",
  text_size = 18,
  text_align = "left",
  text_padding = 10
)

Arguments

gt_object

A gt table object.

colors

A character vector of hex color codes for the bars.

bar_height

The height of the bars in pixels. Default is 10px.

bar_width

The width of the bars in percentage. Default is 100%.

bar_align

Alignment of the bars when bar_width is not 100%. Options are 'left', 'center', or 'right'. Default is 'center'.

img

A URL for an image to render in the bar (optional).

img_width

The width of the image in pixels. Default is 30px.

img_height

The height of the image in pixels. Default is 30px.

img_padding

Padding around the image to ensure it's not touching the edges. Default is 10px.

img_align

Alignment of the image within the bar ('left', 'center', 'right'). Default is 'right'.

text

Optional text to display in the bar.

text_weight

Font weight of the text. Default is 'bold' for emphasis.

text_color

Color of the text. Default is '#FFFFFF' (white).

text_size

Font size for the text. Default is 18px.

text_align

Alignment of the text within the bar ('left', 'center', 'right'). Default is 'left'.

text_padding

Padding around the text to ensure it's not touching the edges. Default is 10px.

Value

A gt table with a row of horizontal bars at the top.