Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX in column names of a table in R markdown

Tags:

r

gt

How can I have LaTeX symbols like alpha or delta in column names of html output with gt package.

library(gt)

# Create a data frame
data <- data.frame(
  x = c(1, 2, 3),
  y = c(4, 5, 6)
)

# Set the column names as LaTeX formulas
colnames(data) <- c("$\\alpha$", "$\\beta$")

# Create a gt table
gt(data)

enter image description here

like image 834
Marco Avatar asked Sep 07 '25 08:09

Marco


1 Answers

If you do not mind using unicode, this works but I appreciate it does not use LaTeX equation mode.

library(gt)

# Create a data frame
data <- data.frame(
  x = c(1, 2, 3),
  y = c(4, 5, 6)
)

# Set the column names with unicode
colnames(data) <- c("\u03B1", "\u03B2")

# Create a gt table
gt(data)

enter image description here

like image 112
Peter Avatar answered Sep 09 '25 03:09

Peter