Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Include Arrows and Superscripts in RMardown Table

I am new to R so please spare me. I have a table and I would like to include up and down arrows in one column. I intend to construct a data.frame with one column exclusively up or down arrows. I can print an up arrow using & # 8 6 7 9 ; which yields ⇧ and I can print a down arrow using & # 8 6 8 1 ; which yields ⇩. How cool! However, how can I put this into my data.table in Rmardown? Additionally, any ideas on how I can paste superscripted characters in a column? (I'm using knitr to pdf in RMardown)

like image 791
AaronSzcz Avatar asked Sep 07 '25 10:09

AaronSzcz


1 Answers

This is a solution with kableExtra.

.Rmd file:

---
title: "Untitled"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(kableExtra)
```

```{r}
mtcars[1:4, 1:4] %>%
  mutate(arrows = c("$\\uparrow$", "$\\downarrow$", "$\\rightarrow$", "$\\leftarrow$")) %>% # you can use LaTeX code here (just place it like this: "$\LaTeXcode$") %>%
  mutate(superscript = c("$Example^{test}$", "$R^2$", "$R^2$", "$R^2$")) %>%
  kbl(booktabs = T, linesep = "", escape = F)
```

-output

enter image description here

like image 71
bttomio Avatar answered Sep 10 '25 01:09

bttomio