Skip to content

simple_table

Synopsis

simple_table creates a basic tabular display of raw data from a dataset. It allows users to select specific columns, optionally rename them, and control the alignment and appearance of subheaders.

Example Usage

julia
using SummaryTables

data = (
    id = 1:5,
    name = ["Alice", "Bob", "Charlie", "David", "Eve"],
    age = [34, 29, 42, 37, 25],
    score = [88, 92, 75, 80, 95]
)

simple_table(data)
id name age score
1 Alice 34 88
2 Bob 29 92
3 Charlie 42 75
4 David 37 80
5 Eve 25 95
julia
simple_table(data, [:id => "Identifier", :name => "Full Name", :age => "Age (years)"])
Identifier Full Name Age (years)
1 Alice 34
2 Bob 29
3 Charlie 42
4 David 37
5 Eve 25

Argument 1: table

The first argument can be any object compatible with the Tables.jl API. Some common examples:

DataFrame

julia
using DataFrames
using SummaryTables

data = DataFrame(a = [1, 2, 3], b = ["x", "y", "z"])

simple_table(data)
a b
1 x
2 y
3 z

NamedTuple of Vectors

julia
using SummaryTables

data = (; a = [1, 2, 3], b = ["x", "y", "z"])

simple_table(data)
a b
1 x
2 y
3 z

Vector of NamedTuples

julia
using SummaryTables

data = [(; a = 1, b = "x"), (; a = 2, b = "y"), (; a = 3, b = "z")]

simple_table(data)
a b
1 x
2 y
3 z

Argument 2: columns

The optional second argument selects the columns to display. Each entry is a column name (Symbol or String), optionally paired with a display name, a NumberFormat, or both.

julia
using SummaryTables

data = (; id = 1:3, fraction = [0.123, 0.456, 0.789], count = [1200, 55000, 1_230_000])

simple_table(data, [
    :id => "ID",
    :fraction => NumberFormat(scale = 100, suffix = " %", digits = 3) => "Fraction",
    :count => NumberFormat(magnitudes = :financial),
])
ID Fraction count
1 12.3 % 1.2K
2 45.6 % 55K
3 78.9 % 1.23M

Keyword: halign

Controls the horizontal alignment of column contents. Accepts :left, :right, :center, or a vector of these values (one for each column).

julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, halign = :right, number_format = NumberFormat(mode = :digits))
value sin cos
1 0.841 0.540
2 0.909 -0.416
3 0.141 -0.990
julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, halign = [:left, :right, :right], number_format = NumberFormat(mode = :digits))
value sin cos
1 0.841 0.540
2 0.909 -0.416
3 0.141 -0.990

Keyword: subheaders

Allows specifying subheaders for columns. These must be of the same length as the number of displayed columns.

julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, subheaders = ["Int64", "Float64", "Float64"], halign = :right)
value sin cos
Int64 Float64 Float64
1 0.841 0.54
2 0.909 -0.416
3 0.141 -0.99