Chapter 7 Tables
7.1 Markdown table generator
If you’re making a new table from scratch then the Markdown Table Generator (https://www.tablesgenerator.com/markdown_tables) is a handy tool.
7.2 Table syntax
Tables are a bit more simple in markdown than in latex. I haven’t played around with complex tables much, but it’s straightforward to make a basic one.
Example table:
Table: (\#tab:planck-model) Base $\Lambda$CDM cosmological parameters from @Planck18.
| Parameter | Best fit value | Uncertainty |
|:--------------------|----------:|----------:|
| $\Omega_{b}h^2$ | 0.02233 | 0.00015 |
| $\Omega_{c}h^2$ | 0.1198 | 0.0012 |
| $\Omega_{m}h^2$ | 0.1428 | 0.0011 |
| $H_0$ | 67.37 | 0.54 |
| $\Omega_{m}$ | 0.3147 | 0.0074 |
| Age (Gyr) | 13.801 | 0.024 |
| $z_{re}$ | 7.64 | 0.74 |
| 100$\theta_{*}$ | 1.04108 | 0.00031 |
Important things about tables:
- Captions go at the top and should include the label definition.
- Label syntax is
Table: (\#tab:table-name)
- Columns are delimited by
|
- Justification given by the colons and dashes in the line under the header row.
Parameter | Best fit value | Uncertainty |
---|---|---|
\(\Omega_{b}h^2\) | 0.02233 | 0.00015 |
\(\Omega_{c}h^2\) | 0.1198 | 0.0012 |
\(\Omega_{m}h^2\) | 0.1428 | 0.0011 |
\(H_0\) | 67.37 | 0.54 |
\(\Omega_{m}\) | 0.3147 | 0.0074 |
Age (Gyr) | 13.801 | 0.024 |
\(z_{re}\) | 7.64 | 0.74 |
100\(\theta_{*}\) | 1.04108 | 0.00031 |
7.3 Fancy tables
The kableExtra
package is useful if you want to make fancier tables with things like grouped columns. The documentation is here (it’s a bit sparse…) but I’m including an example here to save you the time googling.
library(kableExtra)
## read the table in from a file
df <- read.csv("lj_table.csv", header = TRUE, row.names = "Element")
## changing the names of my column headings. R starts
## counting at 1
names(df)[1] <- paste("$10^{-21}$ J")
names(df)[2] <- paste("meV")
names(df)[3] <- paste("$10^{-10}$ m")
## fancy formatting
df %>%
kbl(caption = "Lennerd-Jones potentials, apparently. Shamelessly stolen from Sloan's lecture notes.",
align = c("l", "c", "c", "c")) %>%
## only a little table, so stopping it being the full
## width of the page
kable_styling(full_width = F) %>%
## Grouping some columns
add_header_above(c(Element = 1, `$\\epsilon$` = 2, `$\\sigma$` = 1,
`$r_0$` = 1), align = c("l", "c", "c", "c"))
\(10^{-21}\) J | meV | \(10^{-10}\) m | Å | |
---|---|---|---|---|
He | 0.14 | 0.9 | 2.56 | 3.12 |
Ne | 0.49 | 3.1 | 2.75 | 3.36 |
Ar | 1.70 | 10.6 | 3.40 | 4.15 |
To get this to show your table, include the code above inside an r
code chunk. The echo=FALSE
part hides the code but still displays the result (which is probably what you want).
References
Planck Collaboration. 2018, arXiv:180706209, arXiv:1807.06209, https://arxiv.org/abs/1807.06209