borders examples

library(knitr)
library(officedown)
library(flextable)

opts_chunk$set(
  echo = FALSE,
  ft.tabcolsep = 3
)

Blah

dat <- tibble::tribble(
    ~S,   ~T,   ~U,   ~V,   ~W,   ~X,   ~Y,   ~Z,
  "AA", "AA", "AA", "AA", "AA", "AA", "AA", "AA",
  "BB", "AA", "AA", "AA", "AA", "AA", "AA", "AA",
  "CC", "CC", "AA", "AA", "AA", "AA", "AA", "AA",
  "DD", "DD", "DD", "AA", "AA", "AA", "AA", "AA",
  "EE", "EE", "EE", "EE", "AA", "AA", "AA", "AA",
  "FF", "FF", "FF", "FF", "FF", "AA", "AA", "AA",
  "GG", "GG", "GG", "GG", "GG", "GG", "AA", "AA",
  "HH", "HH", "HH", "HH", "HH", "HH", "HH", "AA"
  )
ft <- flextable(dat)
ft <- theme_vader(ft)
ft <- border_outer(ft, border = fp_border_default(width = 2.5, color = "red"))
ft <- border_inner_v(ft, border = fp_border_default(width = 1, color = "cyan"))
ft <- border_inner_h(ft, border = fp_border_default(width = 1, color = "orange"))
ft <- merge_h(ft)
ft <- fix_border_issues(ft)
ft

Blah

ft <- flextable(head(iris, n = 2))
ft <- border_inner_v(ft, part = "all")
ft <- hline(ft,
    i = 1, j = 2:4, part = "body",
    border = officer::fp_border("red")
  )
ft <- hline(ft, 
    i = 1, j = 1:1, part = "body",
    border = officer::fp_border("orange")
  )
ft <- autofit(ft)
ft

\pagebreak

Blah

dat <- data.frame(
  s = c("a", "a", "a", "a", "b", "b", "b", "b"),
  t = c("AA", "AA", "AA", "BB", "BB", "BB", "CC", "CC"),
  u = c("DD", "DD", "DD", "DD", "DD", "DD", "DD", "DD"),
  v = c("DD", "EE", "EE", "DD", "EE", "EE", "EE", "DD"),
  w = c("DD", "EE", "EE", "DD", "EE", "EE", "EE", "DD"),
  x = c("DD", "DD", "DD", "DD", "DD", "DD", "DD", "DD")
)
ft <- flextable(dat)
ft <- border_outer(ft, border = fp_border_default(width = 2.5, color = "red"))
ft <- border_inner_v(ft, border = fp_border_default(width = 1, color = "cyan"))
ft <- border_inner_h(ft, border = fp_border_default(width = 1, color = "orange"))
ft <- merge_v(ft, j = 1:2)
ft <- merge_h(ft)
ft <- fix_border_issues(ft)
ft

Blah

ft <- flextable(dat)
ft <- theme_vader(ft)
ft

\pagebreak

Blah

ft <- border_outer(ft, border = fp_border_default(width = 2.5, color = "red"))
ft <- border_inner_v(ft, border = fp_border_default(width = 1, color = "cyan"))
ft <- border_inner_h(ft, border = fp_border_default(width = 1, color = "orange"))
ft <- merge_v(ft, j = 1:2)
ft <- merge_h(ft)
ft <- fix_border_issues(ft)
ft

Blah

dt <- data.frame(
  stringsAsFactors = FALSE,
  V1 = c("OOOOOOOO", "OOOOOOOO", "OOOOOOOO"),
  V2 = c("XXX", "XXX", "YYY"),
  V3 = c("ZZZ", "ZZZ", "ZZZ"),
  V4 = c("XXXX XXXX XXXX XXXX",
         "XXXX XXXX XXXX XXXX",
         "XXXX XXXX XXXX XXXX")
)

dt |>
  flextable() |>
  set_table_properties(
    layout = "autofit", width = .8,
    opts_pdf = list(tabcolsep = 3)
  ) |>
  merge_v(j = ~ V1 + V2) |>
  valign(valign = "top", part = "all") |>
  border_inner_h(part = "all") |>
  border_inner_v(part = "all") |>
  border_outer(part = "all", border = fp_border_default(color = "red")) |>
  autofit() |>
  fix_border_issues(part = "all")

blouh

ft <- as_flextable(cars)
ft <- theme_zebra(ft)
ft <- hline(ft, j = 2, part = "body")
ft

kable

kable(head(iris))


Try the flextable package in your browser

Any scripts or data that you put into this service are public.

flextable documentation built on Oct. 30, 2024, 9:15 a.m.