API
Complete API reference for StyledTables.jl. All exported symbols are listed below, grouped by kind.
StyledTables.StyledTable Type
mutable struct StyledTableContains table build specifications for the DataFrame to be rendered.
Construct with StyledTable, apply modifier functions, then call render:
tbl = StyledTable(df)
cols_label!(tbl, :x => "X")
tab_header!(tbl, "Title")
render(tbl)data::DataFrame: Source data.col_labels::Dict{Symbol, Any}: Display labels keyed by column name.col_alignments::Dict{Symbol, Symbol}: Horizontal alignment (:left,:center,:right) keyed by column name.spanners::Vector{StyledTables.Spanner}: Spanner header definitions.rowgroup_col::Union{Nothing, Symbol}: Column used for row grouping, ornothing.rowgroup_indent_pt::Float64: Left indent applied to data rows inside a group (points).rowgroup_full_width::Bool: Whentrue, row-group label rows span the full table width instead of the first cell only.stub_col::Union{Nothing, Symbol}: Column designated as the stub (row-label column), ornothing.header::Union{Nothing, StyledTables.TableHeader}: Title/subtitle definition, ornothing.footnotes::Vector{Any}: Table-level footnote texts.col_formatters::Dict{Symbol, Function}: Per-column formatter functions.col_styles::Dict{Symbol, StyledTables.ColStyleOverride}: Per-column inline style overrides.col_style_fns::Dict{Symbol, Function}: Per-column conditional style functionsf(raw_value) -> Union{Nothing, NamedTuple}.col_footnotes::Dict{Symbol, Any}: Per-column footnote annotations.hidden_cols::Set{Symbol}: Columns excluded from the rendered output.stubhead_label::Any: Label for the stub column header, ornothing.sourcenotes::Vector{Any}: Source-note lines appended below the table body.postprocessors::Vector{Any}: SummaryTables postprocessors applied during rendering.round_digits::Union{Nothing, Int64}: Digits to round to, ornothing(SummaryTables defaults to 3).round_mode::Union{Nothing, Symbol}: Global rounding mode (:auto,:digits,:sigdigits), ornothing.trailing_zeros::Union{Nothing, Bool}:trueto pad with trailing zeros when rounding;nothingdefers to SummaryTables.
StyledTables.StyledTable Method
StyledTable(data) -> StyledTableWrap a DataFrame (or any Tables.jl-compatible table) in a StyledTable.
Returns a StyledTable with default settings. Apply modifier functions and call render to produce a SummaryTables.Table.
Arguments
data: aDataFrameor any Tables.jl-compatible table.
Returns
A StyledTable.
See also: render, cols_label!, tab_header!.
Examples
tbl = StyledTable(df)
tab_header!(tbl, "My Table")
render(tbl)StyledTables.cols_align! Method
cols_align!(
tbl::StyledTable,
d::Union{AbstractDict{Symbol, Symbol}, AbstractDict{<:AbstractString, Symbol}, AbstractVector{<:Pair{Symbol, Symbol}}, AbstractVector{<:Pair{<:AbstractString, Symbol}}, AbstractVector{<:Pair{Vector{Symbol}, Symbol}}, AbstractVector{<:Pair{<:AbstractVector{<:AbstractString}, Symbol}}}
) -> StyledTableSet alignment from a dict or vector of col => halign pairs.
Arguments
tbl: theStyledTableto modify.d: anAbstractDictorAbstractVectorofcol => halignpairs.
Returns
tbl (modified in place).
Examples
tbl = StyledTable(df)
cols_align!(tbl, Dict(:x => :right, :y => :center))
render(tbl)StyledTables.cols_align! Method
cols_align!(tbl::StyledTable, args::Pair...) -> StyledTableSet horizontal alignment for one or more columns.
Each argument is a col => halign pair, where col is a Symbol matching a column name and halign is one of :left, :center, or :right.
Arguments
tbl: theStyledTableto modify.args: one or morecol => halignpairs.
Returns
tbl (modified in place).
Examples
tbl = StyledTable(df)
cols_align!(tbl, :x => :right, :y => :center)
render(tbl)StyledTables.cols_hide! Method
cols_hide!(tbl::StyledTable, cols::Symbol...) -> StyledTableRemove columns from the rendered output without modifying the DataFrame.
Hidden columns remain accessible for grouping or formatting, but do not appear in the rendered table. Commonly paired with tab_rowgroup!.
Arguments
tbl: theStyledTableto modify.cols: one or more column names to hide.
Returns
tbl (modified in place).
See also: tab_rowgroup!.
Examples
tbl = StyledTable(df)
tab_rowgroup!(tbl, :group)
cols_hide!(tbl, :group)
render(tbl)StyledTables.cols_label! Method
cols_label!(
tbl::StyledTable,
d::Union{AbstractDict{Symbol, Symbol}, AbstractDict{<:AbstractString, <:AbstractString}, AbstractDict{<:AbstractString, Symbol}, AbstractDict{Symbol, <:AbstractString}, AbstractVector{<:Pair{Symbol, Symbol}}, AbstractVector{<:Pair{<:AbstractString, <:AbstractString}}, AbstractVector{<:Pair{<:AbstractString, Symbol}}}
) -> StyledTableRename columns using a dict or vector of pairs.
Arguments
tbl: theStyledTableto modify.d: aDictor vector ofcol => labelpairs specifying columns and their labels.
Returns
tbl (modified in place).
See also: cols_align!, cols_hide!.
Examples
label_dict = Dict(:bmi => "BMI (kg/m²)", :sbp => "Systolic BP")
tbl = StyledTable(df)
cols_label!(tbl, label_dict)
render(tbl)StyledTables.fmt! Method
fmt!(f::Function, tbl::StyledTable, cols) -> StyledTableApply a custom formatter function to values in cols.
f receives the raw cell value and returns a display-ready value. Return x unchanged for missing to let sub_missing! handle it.
Arguments
f: formatter:f(value) -> Any.tbl: theStyledTableto modify.cols: column name(s) to format.
Returns
tbl (modified in place).
See also: fmt_number!, fmt_percent!, fmt_integer!.
Examples
tbl = StyledTable(df)
fmt!(x -> "≈$(round(Int, x))", tbl, [:x])
render(tbl)StyledTables.fmt_integer! Method
fmt_integer!(tbl::StyledTable, cols) -> AnyRound values in cols to the nearest integer and format without a decimal point.
Arguments
tbl: theStyledTableto modify.
Returns
tbl (modified in place).
See also: fmt_number!, fmt_percent!, fmt!.
Examples
tbl = StyledTable(df)
fmt_integer!(tbl, [:count])
render(tbl)StyledTables.fmt_number! Method
fmt_number!(
tbl::StyledTable,
cols;
digits,
trailing_zeros
) -> AnyFormat values in cols to a fixed number of decimal places.
Arguments
tbl: theStyledTableto modify.cols: column name(s) to format — a singleSymbolor anAbstractVector{Symbol}.
Keywords
digits: number of decimal places (default2).trailing_zeros: keep trailing zeros (defaulttrue).
Returns
tbl (modified in place).
See also: fmt_percent!, fmt_integer!, fmt!.
Examples
tbl = StyledTable(df)
fmt_number!(tbl, [:x]; digits = 2)
render(tbl)StyledTables.fmt_percent! Method
fmt_percent!(
tbl::StyledTable,
cols;
digits,
scale,
suffix
) -> AnyFormat values in cols as percentage strings.
Multiplies each value by scale, formats to digits decimal places, and appends suffix.
Arguments
tbl: theStyledTableto modify.
Keywords
digits: decimal places for the percentage (default1).scale: multiplier applied before formatting (default100).suffix: string appended after the number (default"%").
Returns
tbl (modified in place).
See also: fmt_number!, fmt_integer!, fmt!.
Examples
tbl = StyledTable(df)
fmt_percent!(tbl, [:rate]; digits = 1)
render(tbl)StyledTables.render Method
render(tbl::StyledTable) -> TableConvert a StyledTable into a renderable SummaryTables.Table.
Applies all registered modifiers (labels, spanners, formatters, styles, row groups) and assembles the cell matrix. The result renders to HTML, LaTeX, and Typst.
In interactive contexts, render is optional: StyledTable defines Base.show methods that call it automatically.
Arguments
tbl: aStyledTableconfigured with modifier functions.
Returns
A SummaryTables.Table (a Matrix{Cell} with header/footer metadata).
See also: StyledTable, tab_header!, cols_label!.
Examples
using StyledTables, DataFrames
df = DataFrame(a = [1, 2], b = ["x", "y"])
tbl = StyledTable(df)
cols_label!(tbl, :a => "A", :b => "B")
render(tbl)StyledTables.sub_missing! Method
sub_missing!(tbl::StyledTable, r) -> StyledTableReplace missing values with a display placeholder.
Arguments
tbl: theStyledTableto modify.r: replacement display value
Returns
tbl (modified in place).
See also: fmt!.
Examples
tbl = StyledTable(df)
sub_missing!(tbl)
render(tbl)StyledTables.tab_footnote! Method
tab_footnote!(
tbl::StyledTable,
d::Union{AbstractDict{<:AbstractString, <:Union{Vector{Symbol}, Vector{<:AbstractString}}}, AbstractVector{<:Pair{<:AbstractString, <:Union{Vector{Symbol}, Vector{<:AbstractString}}}}}
) -> StyledTableAdd footnotes from a dict or vector of pairs.
Arguments
tbl: theStyledTableto modify.d: anAbstractDictorAbstractVectorofPairs mapping text to column names.
Returns
tbl (modified in place).
See also: tab_spanner!, tab_header!, tab_stub!.
Examples
tbl = StyledTable(df)
tab_footnote!(tbl, Dict(
"measured each month" => [:efficacy, :safety],
"in years" => [:age])
)
render(tbl)StyledTables.tab_footnote! Method
tab_footnote!(
tbl::StyledTable,
args::Pair...
) -> StyledTableAdd footnotes to the table.
Footnotes refer to specific columns. For placing general notes under the table, see tab_sourcenote!.
Arguments
tbl: theStyledTableto modify.args: one or moretext => column(s)pairs.
Returns
tbl (modified in place).
See also: tab_sourcenote!, tab_header!.
Examples
tbl = StyledTable(df)
tab_footnote!(tbl, "PPP adjusted" => :gdp)
render(tbl)StyledTables.tab_header! Method
tab_header!(
tbl::StyledTable,
title;
subtitle
) -> StyledTableAdd a title and optional subtitle above the column headers.
The title renders bold; the subtitle renders italic.
Arguments
tbl: theStyledTableto modify.title: main heading text.
Keywords
subtitle: secondary heading text, ornothing(default).
Returns
tbl (modified in place).
See also: tab_spanner!, tab_sourcenote!, tab_footnote!.
Examples
tbl = StyledTable(df)
tab_header!(tbl, "My Table"; subtitle = "Subtitle here")
render(tbl)StyledTables.tab_rowgroup! Method
tab_rowgroup!(
tbl::StyledTable,
col::Symbol;
indent_pt,
full_width
) -> StyledTableGroup rows by distinct values in a column.
A bold group-label row precedes each new group value. Data rows are indented by indent_pt points. Hide the grouping column afterwards with cols_hide!.
Arguments
tbl: theStyledTableto modify.col: column whose distinct values define the groups.
Keywords
indent_pt: left indent for data rows within a group (default12).full_width: whether group-label rows span the entire table width (defaultfalse).
Returns
tbl (modified in place).
See also: cols_hide!, tab_stub!.
Examples
tbl = StyledTable(df)
tab_rowgroup!(tbl, :category)
cols_hide!(tbl, :category)
render(tbl)StyledTables.tab_sourcenote! Method
tab_sourcenote!(tbl::StyledTable, text) -> StyledTableAdd a source-note line in the table footer.
Source notes span the full table width and are left-aligned. Each call appends another line.
Arguments
tbl: theStyledTableto modify.text: source note text.
Returns
tbl (modified in place).
See also: tab_footnote!, tab_header!.
Examples
tbl = StyledTable(df)
tab_sourcenote!(tbl, "Data: World Bank Open Data")
render(tbl)StyledTables.tab_spanner! Method
tab_spanner!(
tbl::StyledTable,
d::Union{AbstractDict{Symbol, Vector{Symbol}}, AbstractDict{Symbol, Symbol}, AbstractDict{Multiline, Symbol}, AbstractDict{<:AbstractString, <:AbstractVector{<:AbstractString}}, AbstractDict{Symbol, <:AbstractVector{<:AbstractString}}, AbstractDict{<:AbstractString, Vector{Symbol}}, AbstractDict{<:AbstractString, <:AbstractString}, AbstractDict{Symbol, <:AbstractString}, AbstractDict{<:AbstractString, Symbol}, AbstractDict{Multiline, <:AbstractString}, AbstractVector{<:Pair{<:AbstractString, <:AbstractVector{<:AbstractString}}}, AbstractVector{<:Pair{Symbol, Vector{Symbol}}}, AbstractVector{<:Pair{Symbol, <:AbstractVector{<:AbstractString}}}, AbstractVector{<:Pair{<:AbstractString, Vector{Symbol}}}, AbstractVector{<:Pair{<:AbstractString, <:AbstractString}}, AbstractVector{<:Pair{Symbol, <:AbstractString}}, AbstractVector{<:Pair{<:AbstractString, Symbol}}, AbstractVector{<:Pair{Symbol, Symbol}}, AbstractVector{<:Pair{Multiline, Symbol}}, AbstractVector{<:Pair{Multiline, <:AbstractString}}};
level
) -> StyledTableAdd spanning headers from a dict or vector of pairs.
Arguments
tbl: theStyledTableto modify.d: anAbstractDictorAbstractVectorpairing spanner labels to column names.level: the spanner row applied to every entry ind(default1).
Returns
tbl (modified in place).
See also: tab_spanner!, tab_header!, tab_stub!.
Examples
tbl = StyledTable(df)
tab_spanner!(tbl, Dict(
"Outcomes" => [:efficacy, :safety],
"Demographics" => [:age, :sex])
)
render(tbl)StyledTables.tab_stub! Method
tab_stub!(tbl::StyledTable, col::Symbol) -> StyledTableMark a column as the stub (row-label column).
The stub header is not bolded. Use tab_stubhead! to label it.
Arguments
tbl: theStyledTableto modify.col: name of the column to use as the stub.
Returns
tbl (modified in place).
See also: tab_stubhead!, tab_rowgroup!.
Examples
tbl = StyledTable(df)
tab_stub!(tbl, :drug)
render(tbl)StyledTables.tab_stubhead! Method
tab_stubhead!(tbl::StyledTable, label) -> StyledTableSet the stub column header label.
Requires a prior call to tab_stub!.
Arguments
tbl: theStyledTableto modify.label: display text for the stub header cell.
Returns
tbl (modified in place).
See also: tab_stub!.
Examples
tbl = StyledTable(df)
tab_stub!(tbl, :drug)
tab_stubhead!(tbl, "Drug Name")
render(tbl)Conventions
StyledTables.jl uses two conventions for specifying columns with => pairs, each reflecting a different kind of operation.
cols_* functions: column → value
Column modifier functions take the column as subject. Target a column and assign a property to it:
cols_label!(tbl, :bmi => "BMI (kg/m²)")This mirrors the old => new convention of DataFrames.rename!: what's being modified comes first.
tab_* functions: annotation → columns
Table-level annotation functions take the annotation as subject. Define an annotation and specify which columns it covers:
tab_spanner!(tbl, "Demographics" => [:age, :sex])
tab_footnote!(tbl, "PPP adjusted" => [:gdp, :gni])The annotation comes first because it is the entity being created; the columns define its scope (and apart from that, it is also a whole lot more readable!).
In short, cols_* functions put the column first; tab_* functions put the label or annotation first.