from great_tables import GT
from great_tables.data import gtcars
= gtcars[["model", "year", "hp", "trq"]].head(5)
gtcars_mini
(="model")
GT(gtcars_mini, rowname_col="car")
.tab_stubhead(label )
GT.tab_stubhead
self, label) GT.tab_stubhead(
Add label text to the stubhead.
Add a label to the stubhead of a table. The stubhead is the lone element that is positioned left of the column labels, and above the stub. If a stub does not exist, then there is no stubhead (so no change will be made when using this method in that case). We have the flexibility to use Markdown formatting for the stubhead label (through use of the md()
helper function). Furthermore, we can use HTML for the stubhead label so long as we also use the html()
helper function.
Parameters
Returns
: GT
-
The GT object is returned. This is the same object that the method is called on so that we can facilitate method chaining.
Examples
Using a small subset of the gtcars
dataset, we can create a table with row labels. Since we have row labels in the stub (via use of rowname_col="model"
in the GT()
call) we have a stubhead, so, let’s add a stubhead label ("car"
) with the tab_stubhead()
method to describe what’s in the stub.
We can also use Markdown formatting for the stubhead label. In this example, we’ll use md("*Car*")
to make the label italicized.
from great_tables import GT, md
from great_tables.data import gtcars
(="model")
GT(gtcars_mini, rowname_col=md("*Car*"))
.tab_stubhead(label )
Car | year | hp | trq |
---|---|---|---|
GT | 2017.0 | 647.0 | 550.0 |
458 Speciale | 2015.0 | 597.0 | 398.0 |
458 Spider | 2015.0 | 562.0 | 398.0 |
458 Italia | 2014.0 | 562.0 | 398.0 |
488 GTB | 2016.0 | 661.0 | 561.0 |