nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
179 stars 18 forks source link

Document that greek letters (and math symbols) can be used in tables #70

Closed nutterb closed 7 years ago

nutterb commented 7 years ago

I received this following request via e-mail;

Can you include greek letters in a pixiedust table that you want to knit in word using R markdown? If so this would be a great addition to one of your very thorough vignettes.

My response was:

To get a greek symbol, you should only need to insert the text you would use for the symbol in math mode. This will usually mean doubling up your backslashes. I’ve drawn up some sample code below. I’ve assumed you’re familiar with the basics of LaTeX (if you’re not, you can find some pretty good tutorials online).


---
title: "Untitled"
output: word_document

---

## Manually constructed table

| name  | greek    |
|-------|----------|
| alpha | $\alpha$ |
| beta  | $\beta$  |
| gamma | $\gamma$ |
| delta | $\delta$ |

## Programmatically constructed table
`{r}
library(dplyr)
library(pixiedust)

data.frame(name = c("alpha", "beta", "gamma", "delta"),
                stringsAsFactors = FALSE) %>%
  mutate(greek = sprintf("$\\%s$", name)) %>%
  dust()