Skip to content

Getting Started

Installation

julia
import Pkg
Pkg.add("StyledTables")

Your first table

The workflow almost always starts with a DataFrame and ends with render().

julia
using StyledTables, DataFrames

df = DataFrame(
    treatment = ["Placebo", "Low Dose", "High Dose"],
    n = [30, 30, 30],
    response = [0.12, 0.38, 0.61],
)

tbl = StyledTable(df)
render(tbl)
treatment n response
Placebo 30 0.12
Low Dose 30 0.38
High Dose 30 0.61

StyledTable(df) wraps the DataFrame. render() converts it to a SummaryTables.Table that can be saved as html, LaTeX, typst or docx (see the SummaryTables.jl docs for further detail).

Adding a title

julia
tbl = StyledTable(df)
tab_header!(tbl, "Treatment Response"; subtitle = "Phase II Clinical Trial")
render(tbl)
Treatment Response
Phase II Clinical Trial
treatment n response
Placebo 30 0.12
Low Dose 30 0.38
High Dose 30 0.61

Relabeling and aligning columns

julia
labels = Dict(
    :treatment => "Treatment arm",
    :n => "N",
    :response => "Response rate",
)

tbl = StyledTable(df)
tab_header!(tbl, "Treatment Response")
cols_label!(tbl, labels)
cols_align!(tbl, :n => :center, :response => :center)
render(tbl)
Treatment Response
Treatment arm N Response rate
Placebo 30 0.12
Low Dose 30 0.38
High Dose 30 0.61

Grouping columns under a spanner

julia
tab_spanner!(tbl, "Results" => [:n, :response])
render(tbl)
Treatment Response
Results
Treatment arm N Response rate
Placebo 30 0.12
Low Dose 30 0.38
High Dose 30 0.61

Formatting numbers

julia
fmt_percent!(tbl, [:response]; digits = 1)
render(tbl)
Treatment Response
Results
Treatment arm N Response rate
Placebo 30 12.0%
Low Dose 30 38.0%
High Dose 30 61.0%