knitr::opts_chunk$set(echo = TRUE)

中文测试

library(huxtable)
library(dplyr)
ht <- hux(
  Employee     = c('John Smith中文', 'Jane Doe', 'David Hugh-Jones'),
  Salary       = c(50000L, 50000L, 40000L),
  add_colnames = TRUE
)

# utf8_to_rtf <- function (chr) {
#   u16_int <- function (x) {
#     x <- utf8ToInt(x)
#     x[x > 32767] <- x[x > 32767] - 65535L
#     x
#   }
#   vapply(chr, function (x) paste0("\\u", u16_int(x), "?", collapse = ""), 
#          character(1))
# }

# ht$Employee <- utf8_to_rtf(ht$Employee)

ht  %>%
  set_right_padding(1)           %>%
  set_left_padding(1)            %>% 
  set_bold(1, 1:2, TRUE)          %>%
  set_top_border(1, 1:2, 1)    %>%
  set_bottom_border(1, 1:2, 1)    %>%
  set_bottom_border(4, 1:2, 1)    %>%
  set_align(1:3, 2, 'right')      %>%
  set_width(1) %>%
  set_number_format(everywhere, -1, 2)            %>% 
  set_number_format(everywhere, 1, NA)            %>% 
  set_escape_contents(everywhere, 1, FALSE) %>% 
  # set_font(1:4, 1:2, value = "Courier New") %>%
  set_font(1:4, 1:2, value = "Times New Roman") %>%
  set_font_size(1:4, 1:2, value = 9) %>%
  set_caption('1.1 Employee table') %>%
  set_caption_pos("topleft")


hughjonesd/huxtable documentation built on Feb. 17, 2024, 12:20 a.m.