Skip to content

Sports Cars Performance Table

This example compares sports cars across performance metrics. We hide auxiliary columns, group by origin country, add a performance spanner, format prices, and highlight them with bold styling.

The data

julia
using StyledTables, DataFrames

cars = DataFrame(
    origin = ["Italy", "Italy", "Germany", "Germany", "UK", "UK"],
    make = ["Ferrari", "Lamborghini", "Porsche", "BMW", "McLaren", "Aston Martin"],
    model = ["488 GTB", "Huracán", "911 GT3", "M8", "720S", "Vantage"],
    msrp_eur = [280_000, 210_000, 180_000, 130_000, 220_000, 155_000],
    year = [2022, 2022, 2022, 2022, 2022, 2022],
    hp = [660, 610, 503, 617, 710, 503],
    trq_nm = [760, 560, 470, 750, 770, 625],
    mpg = [15, 13, 22, 19, 21, 20],
)
6×8 DataFrame
Roworiginmakemodelmsrp_euryearhptrq_nmmpg
StringStringStringInt64Int64Int64Int64Int64
1ItalyFerrari488 GTB280000202266076015
2ItalyLamborghiniHuracán210000202261056013
3GermanyPorsche911 GT3180000202250347022
4GermanyBMWM8130000202261775019
5UKMcLaren720S220000202271077021
6UKAston MartinVantage155000202250362520

Step 1: Basic table with row groups

Group by :origin and hide the origin and year columns.

julia
label_dict = Dict(
    :make => "Make",
    :model => "Model",
    :msrp_eur => "MSRP (€)",
    :hp => "HP",
    :trq_nm => "Torque (Nm)",
    :mpg => "MPG",
)

tbl = StyledTable(cars)
tab_rowgroup!(tbl, :origin)
cols_hide!(tbl, :origin, :year)
cols_label!(tbl, label_dict)
render(tbl)
Make Model MSRP (€) HP Torque (Nm) MPG
Italy
Ferrari 488 GTB 280000 660 760 15
Lamborghini Huracán 210000 610 560 13
Germany
Porsche 911 GT3 180000 503 470 22
BMW M8 130000 617 750 19
UK
McLaren 720S 220000 710 770 21
Aston Martin Vantage 155000 503 625 20

Step 2: Add a spanner for performance metrics

julia
tab_spanner!(tbl, "Performance" => [:hp, :trq_nm, :mpg])
render(tbl)
Performance
Make Model MSRP (€) HP Torque (Nm) MPG
Italy
Ferrari 488 GTB 280000 660 760 15
Lamborghini Huracán 210000 610 560 13
Germany
Porsche 911 GT3 180000 503 470 22
BMW M8 130000 617 750 19
UK
McLaren 720S 220000 710 770 21
Aston Martin Vantage 155000 503 625 20

Step 3: Reorder, format, and highlight

Format MSRP with a currency prefix, right-align numeric columns, bold the price values, and annotate the MPG column.

julia
fmt!(tbl, :msrp_eur) do x
    replace(string(x), r"(\d)(?=(\d{3})+$)" => s"\1,") * "€"
end
cols_align!(tbl, [:msrp_eur, :hp, :trq_nm, :mpg] => :right)
tab_style!(tbl, :msrp_eur; bold = true)
tab_footnote!(tbl, "City/highway combined estimate" => :mpg)
tab_sourcenote!(tbl, "Source: manufacturer specifications")
render(tbl)
Performance
Make Model MSRP (€) HP Torque (Nm) MPG1
Italy
Ferrari 488 GTB 280,000€ 660 760 15
Lamborghini Huracán 210,000€ 610 560 13
Germany
Porsche 911 GT3 180,000€ 503 470 22
BMW M8 130,000€ 617 750 19
UK
McLaren 720S 220,000€ 710 770 21
Aston Martin Vantage 155,000€ 503 625 20
Source: manufacturer specifications
1 City/highway combined estimate

The table groups cars by origin, spans the three performance columns, formats MSRP with a thousands separator and currency symbol, and bolds prices for emphasis. The MPG footnote clarifies the measurement basis.