Skip to content

API

Complete API reference for StyledTables.jl. All exported symbols are listed below, grouped by kind.

StyledTables.StyledTable Type
julia
mutable struct StyledTable

Contains table build specifications for the DataFrame to be rendered.

Construct with StyledTable, apply modifier functions, then call render:

julia
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, or nothing.

  • rowgroup_indent_pt::Float64: Left indent applied to data rows inside a group (points).

  • rowgroup_full_width::Bool: When true, 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), or nothing.

  • header::Union{Nothing, StyledTables.TableHeader}: Title/subtitle definition, or nothing.

  • 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 functions f(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, or nothing.

  • 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, or nothing (SummaryTables defaults to 3).

  • round_mode::Union{Nothing, Symbol}: Global rounding mode (:auto, :digits, :sigdigits), or nothing.

  • trailing_zeros::Union{Nothing, Bool}: true to pad with trailing zeros when rounding; nothing defers to SummaryTables.

source
StyledTables.StyledTable Method
julia
StyledTable(data) -> StyledTable

Wrap 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: a DataFrame or any Tables.jl-compatible table.

Returns

A StyledTable.

See also: render, cols_label!, tab_header!.

Examples

julia
tbl = StyledTable(df)
tab_header!(tbl, "My Table")
render(tbl)
source
StyledTables.cols_align! Method
julia
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}}}
) -> StyledTable

Set alignment from a dict or vector of col => halign pairs.

Arguments

  • tbl: the StyledTable to modify.

  • d: an AbstractDict or AbstractVector of col => halign pairs.

Returns

tbl (modified in place).

Examples

julia
tbl = StyledTable(df)
cols_align!(tbl, Dict(:x => :right, :y => :center))
render(tbl)
source
StyledTables.cols_align! Method
julia
cols_align!(tbl::StyledTable, args::Pair...) -> StyledTable

Set 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: the StyledTable to modify.

  • args: one or more col => halign pairs.

Returns

tbl (modified in place).

Examples

julia
tbl = StyledTable(df)
cols_align!(tbl, :x => :right, :y => :center)
render(tbl)
source
StyledTables.cols_hide! Method
julia
cols_hide!(tbl::StyledTable, cols::Symbol...) -> StyledTable

Remove 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: the StyledTable to modify.

  • cols: one or more column names to hide.

Returns

tbl (modified in place).

See also: tab_rowgroup!.

Examples

julia
tbl = StyledTable(df)
tab_rowgroup!(tbl, :group)
cols_hide!(tbl, :group)
render(tbl)
source
StyledTables.cols_label! Method
julia
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}}}
) -> StyledTable

Rename columns using a dict or vector of pairs.

Arguments

  • tbl: the StyledTable to modify.

  • d: a Dict or vector of col => label pairs specifying columns and their labels.

Returns

tbl (modified in place).

See also: cols_align!, cols_hide!.

Examples

julia
label_dict = Dict(:bmi => "BMI (kg/m²)", :sbp => "Systolic BP")
tbl = StyledTable(df)
cols_label!(tbl, label_dict)
render(tbl)
source
StyledTables.fmt! Method
julia
fmt!(f::Function, tbl::StyledTable, cols) -> StyledTable

Apply 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: the StyledTable to modify.

  • cols: column name(s) to format.

Returns

tbl (modified in place).

See also: fmt_number!, fmt_percent!, fmt_integer!.

Examples

julia
tbl = StyledTable(df)
fmt!(x -> "≈$(round(Int, x))", tbl, [:x])
render(tbl)
source
StyledTables.fmt_integer! Method
julia
fmt_integer!(tbl::StyledTable, cols) -> Any

Round values in cols to the nearest integer and format without a decimal point.

Arguments

Returns

tbl (modified in place).

See also: fmt_number!, fmt_percent!, fmt!.

Examples

julia
tbl = StyledTable(df)
fmt_integer!(tbl, [:count])
render(tbl)
source
StyledTables.fmt_number! Method
julia
fmt_number!(
    tbl::StyledTable,
    cols;
    digits,
    trailing_zeros
) -> Any

Format values in cols to a fixed number of decimal places.

Arguments

  • tbl: the StyledTable to modify.

  • cols: column name(s) to format — a single Symbol or an AbstractVector{Symbol}.

Keywords

  • digits: number of decimal places (default 2).

  • trailing_zeros: keep trailing zeros (default true).

Returns

tbl (modified in place).

See also: fmt_percent!, fmt_integer!, fmt!.

Examples

julia
tbl = StyledTable(df)
fmt_number!(tbl, [:x]; digits = 2)
render(tbl)
source
StyledTables.fmt_percent! Method
julia
fmt_percent!(
    tbl::StyledTable,
    cols;
    digits,
    scale,
    suffix
) -> Any

Format values in cols as percentage strings.

Multiplies each value by scale, formats to digits decimal places, and appends suffix.

Arguments

Keywords

  • digits: decimal places for the percentage (default 1).

  • scale: multiplier applied before formatting (default 100).

  • suffix: string appended after the number (default "%").

Returns

tbl (modified in place).

See also: fmt_number!, fmt_integer!, fmt!.

Examples

julia
tbl = StyledTable(df)
fmt_percent!(tbl, [:rate]; digits = 1)
render(tbl)
source
StyledTables.render Method
julia
render(tbl::StyledTable) -> Table

Convert 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

Returns

A SummaryTables.Table (a Matrix{Cell} with header/footer metadata).

See also: StyledTable, tab_header!, cols_label!.

Examples

julia
using StyledTables, DataFrames
df = DataFrame(a = [1, 2], b = ["x", "y"])
tbl = StyledTable(df)
cols_label!(tbl, :a => "A", :b => "B")
render(tbl)
source
StyledTables.sub_missing! Method
julia
sub_missing!(tbl::StyledTable, r) -> StyledTable

Replace missing values with a display placeholder.

Arguments

  • tbl: the StyledTable to modify.

  • r: replacement display value

Returns

tbl (modified in place).

See also: fmt!.

Examples

julia
tbl = StyledTable(df)
sub_missing!(tbl)
render(tbl)
source
StyledTables.tab_footnote! Method
julia
tab_footnote!(
    tbl::StyledTable,
    d::Union{AbstractDict{<:AbstractString, <:Union{Vector{Symbol}, Vector{<:AbstractString}}}, AbstractVector{<:Pair{<:AbstractString, <:Union{Vector{Symbol}, Vector{<:AbstractString}}}}}
) -> StyledTable

Add footnotes from a dict or vector of pairs.

Arguments

  • tbl: the StyledTable to modify.

  • d: an AbstractDict or AbstractVector of Pairs mapping text to column names.

Returns

tbl (modified in place).

See also: tab_spanner!, tab_header!, tab_stub!.

Examples

julia
tbl = StyledTable(df)
tab_footnote!(tbl, Dict(
    "measured each month" => [:efficacy, :safety],
    "in years" => [:age])
)
render(tbl)
source
StyledTables.tab_footnote! Method
julia
tab_footnote!(
    tbl::StyledTable,
    args::Pair...
) -> StyledTable

Add footnotes to the table.

Footnotes refer to specific columns. For placing general notes under the table, see tab_sourcenote!.

Arguments

  • tbl: the StyledTable to modify.

  • args: one or more text => column(s) pairs.

Returns

tbl (modified in place).

See also: tab_sourcenote!, tab_header!.

Examples

julia
tbl = StyledTable(df)
tab_footnote!(tbl, "PPP adjusted" => :gdp)
render(tbl)
source
StyledTables.tab_header! Method
julia
tab_header!(
    tbl::StyledTable,
    title;
    subtitle
) -> StyledTable

Add a title and optional subtitle above the column headers.

The title renders bold; the subtitle renders italic.

Arguments

  • tbl: the StyledTable to modify.

  • title: main heading text.

Keywords

  • subtitle: secondary heading text, or nothing (default).

Returns

tbl (modified in place).

See also: tab_spanner!, tab_sourcenote!, tab_footnote!.

Examples

julia
tbl = StyledTable(df)
tab_header!(tbl, "My Table"; subtitle = "Subtitle here")
render(tbl)
source
StyledTables.tab_rowgroup! Method
julia
tab_rowgroup!(
    tbl::StyledTable,
    col::Symbol;
    indent_pt,
    full_width
) -> StyledTable

Group 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: the StyledTable to modify.

  • col: column whose distinct values define the groups.

Keywords

  • indent_pt: left indent for data rows within a group (default 12).

  • full_width: whether group-label rows span the entire table width (default false).

Returns

tbl (modified in place).

See also: cols_hide!, tab_stub!.

Examples

julia
tbl = StyledTable(df)
tab_rowgroup!(tbl, :category)
cols_hide!(tbl, :category)
render(tbl)
source
StyledTables.tab_sourcenote! Method
julia
tab_sourcenote!(tbl::StyledTable, text) -> StyledTable

Add 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

Returns

tbl (modified in place).

See also: tab_footnote!, tab_header!.

Examples

julia
tbl = StyledTable(df)
tab_sourcenote!(tbl, "Data: World Bank Open Data")
render(tbl)
source
StyledTables.tab_spanner! Method
julia
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
) -> StyledTable

Add spanning headers from a dict or vector of pairs.

Arguments

  • tbl: the StyledTable to modify.

  • d: an AbstractDict or AbstractVector pairing spanner labels to column names.

  • level: the spanner row applied to every entry in d (default 1).

Returns

tbl (modified in place).

See also: tab_spanner!, tab_header!, tab_stub!.

Examples

julia
tbl = StyledTable(df)
tab_spanner!(tbl, Dict(
    "Outcomes"     => [:efficacy, :safety],
    "Demographics" => [:age, :sex])
)
render(tbl)
source
StyledTables.tab_stub! Method
julia
tab_stub!(tbl::StyledTable, col::Symbol) -> StyledTable

Mark a column as the stub (row-label column).

The stub header is not bolded. Use tab_stubhead! to label it.

Arguments

  • tbl: the StyledTable to modify.

  • col: name of the column to use as the stub.

Returns

tbl (modified in place).

See also: tab_stubhead!, tab_rowgroup!.

Examples

julia
tbl = StyledTable(df)
tab_stub!(tbl, :drug)
render(tbl)
source
StyledTables.tab_stubhead! Method
julia
tab_stubhead!(tbl::StyledTable, label) -> StyledTable

Set the stub column header label.

Requires a prior call to tab_stub!.

Arguments

  • tbl: the StyledTable to modify.

  • label: display text for the stub header cell.

Returns

tbl (modified in place).

See also: tab_stub!.

Examples

julia
tbl = StyledTable(df)
tab_stub!(tbl, :drug)
tab_stubhead!(tbl, "Drug Name")
render(tbl)
source

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:

julia
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:

julia
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.