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
| Row | origin | make | model | msrp_eur | year | hp | trq_nm | mpg |
|---|---|---|---|---|---|---|---|---|
| String | String | String | Int64 | Int64 | Int64 | Int64 | Int64 | |
| 1 | Italy | Ferrari | 488 GTB | 280000 | 2022 | 660 | 760 | 15 |
| 2 | Italy | Lamborghini | Huracán | 210000 | 2022 | 610 | 560 | 13 |
| 3 | Germany | Porsche | 911 GT3 | 180000 | 2022 | 503 | 470 | 22 |
| 4 | Germany | BMW | M8 | 130000 | 2022 | 617 | 750 | 19 |
| 5 | UK | McLaren | 720S | 220000 | 2022 | 710 | 770 | 21 |
| 6 | UK | Aston Martin | Vantage | 155000 | 2022 | 503 | 625 | 20 |
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.