Template:Static column begin
A template for easily creating a numbered static column to the left of a sorted table. The template also automatically sets the following hidden category:
Note: Also remember to end the static column with {{end}} (see example below).
Redirects[edit]
- {{Template:Static column begin}}
- {{Ranked}}
- {{Rows}} - if you use this redirect, don't forget the "rows" parameter, too.
Usage[edit]
{{Template:Static column begin}} redirects to {{Static column begin}}
{{Rank | rows= | header-text= | header-lines= | header-height= | header-padding= | header-valign= | row-height= | row-header= | text-align= | caption= }} <!-- Your sorted table code here --> {{End}} <!-- Don't forget to add this after your table code! -->
Parameters[edit]
Only the "Rows" parameter is currently obligatory. It has no default value, and not specifying that value will break the static row column.
- Rows
- The number of rows in the column. This must be between 0 and 1050. Can also use Template:Table row counter {{Template:Table row counter}}. See its documentation.
- Header-text
- The text to show in the row-number column header. The default is no text.
- Header-lines
- For example;
header-lines=2
. This maintains row alignment. It also will allow text alone to be zoomed to very high levels without losing row alignment. For example; in Firefox browser go to view menu > zoom > zoom text only > zoom in. If there is just one line in one row, then this parameter is not needed. If there are more lines, then for this to work there must be a header cell that spans (viarow-span
) all the other header cells. It may need breaks added. For the number to use count the number of text and sorting lines. Add the number of header rows minus one (or count the number of solid separation lines in the header). See examples farther down.
- Header-height
- This is rarely needed now. The height of the row-number column header in em units. For example;
header-height=14.19em
. It has to be a precise number in order for rows to stay aligned. For this reason and more theheader-lines
parameter is much easier to use. If pixels are used header-height adds blank space to the top of the header cells.
- Header-padding
- This parameter is not needed, and it is currently not working even when
class=wikitable
andclass=mw-datatable
are removed from the table. The padding of the row-number column header. Addheader-padding=x
in pixels. For example;header-padding=2px
. Don't forget to also add the same padding to the table.
- Header-valign
- The vertical alignment of the text in the row-number column header. Options are
top
,center
andbottom
. The default value when therow-header
parameter is enabled iscenter
, otherwise it isbottom
. See the example below: "Example with row-header formatting."
- Row-height
- The height of each row-number cell. This is not usually necessary. This does not adjust the height of the rows in the main table.
- Row-header
- Enabling this (
y
oryes
) eliminates the space between the 2 tables. It also centers the row-number header text vertically. It makes the background of row number cells darker in order to match the background of the header row. See the example below: "Example with row-header formatting."
- Text-align
- Text alignment of the row numbers. Options are
left
,center
andright
. The default value isright
.
- Caption
- Allows you to specify a caption to appear over the combined table.
Visual Editor and this template. Must add nowiki tags temporarily[edit]
Use the wikitext editor first. WP:Visual Editor (VE) will not work until the {{Rank}} line has nowiki tags added around it first in the wikitext. Or hidden comment tags <!-- -->
.
See Phabricator: T245277. It is titled "VE can't edit tables nested inside a transcluded table (example: row number single-column table from {{Rank}} on English Wikipedia".
Example[edit]
{{Template:Static column begin}} redirects to {{Static column begin}}
- Code
<!-- Static column begin --> {{Rank |rows=2 |header-text=Number |text-align=center}} <!-- Sorted table start --> {| class="wikitable nowrap sortable mw-datatable" !Country !Capital |- |The Netherlands || Amsterdam (although The Hague is the seat of government) |- |France || Paris |} <!-- Sorted table end --> {{End}}
- Resulting table
|
|
- class=mw-datatable
This highlights rows as the mouse hovers over them. This is helpful for quickly scanning rows and headers, but without losing one's place. Run your cursor over the rows in the above table to see.
class=nowrap and table width[edit]
The rows will not align if the table is too wide for the screen it is viewed in. This is because the data and text in the table rows will wrap in order to fit in the screen. Narrow your browser width to see the laddering.
This is true unless class=nowrap
is used. See its use in the above table. But it is better to narrow the table. This way the table may fit in tablets and cell phone screens without extending past the screen.
Example with row-header formatting[edit]
Enabling this (row-header=y
or row-header=yes
) eliminates the space between the 2 tables. It also centers the row-number header text vertically. It makes the background of row number cells darker in order to match the background of the header row.
- Code
<!-- Static column begin --> {{Rank |rows=2 |header-text=Number |row-header=y |text-align=center}} <!-- Sorted table start --> {| class="wikitable nowrap sortable mw-datatable" !Country !Capital |- |The Netherlands || Amsterdam (although The Hague is the seat of government) |- |France || Paris |} <!-- Sorted table end --> {{End}}
- Resulting table
|
|
Header-lines. Example with multi-row headers[edit]
This is taken from a version of List of U.S. states and territories by incarceration and correctional supervision rate.
header-lines=5
is what is needed in this case to allow text-only zooming to very high levels. The left-most header cell spans the other header cells, and it is spanning 4 lines of text, and 1 border line. For a total of 5 lines. Note in the wikitext that breaks <br>
are added to that spanning cell so that there are 5 lines in it. valign=bottom
is added so that the header text is next to the bottom of the header cells.
Below is the header wikitext:
{{Rank|rows=2|header-lines=5|caption=Correctional supervision rates by state, 2016.}} {|class="wikitable nowrap sortable mw-datatable" style=text-align:right; id="states" |- valign=bottom ! rowspan=2|<br><br><br><br>Jurisdiction!! colspan=2|Total !! colspan=2|Community supervision || colspan=2|Incarcerated |-
It produces:
|
|
Header-lines. Example of a very wide table made narrower with a multi-row header[edit]
- Note to developers and template editors: There has to be an easier way. Please create it. Someone with Phabricator clout and understanding might know where and how to suggest on Phabricator that the sorting icon be put on the top or bottom instead of on the side. The header cells would be narrower, and there would be no need for a separate row of sorting cells.
Table made narrower by adding a separate row of sorting cells.
- A table version below from List of countries by past life expectancy
|
|
Row of sorting cells added to narrow the table:
|-
!<br>!! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !!
The country header has rowspan=2 added to it. And some breaks are added to the country header so that it has as many lines as are in the other headers. Each break counts as a line. Borders between header rows count as lines for this calculation.
!rowspan=2|<br><br>Country
header-lines=3 is added as a {{Template:Static column begin}} parameter to allow text-only zooming to very high levels without losing row alignment.
|
|
Example with complex multi-row headers[edit]
- Note to developers and template editors: There has to be an easier way to keep rows aligned. Please create it. Please reinvigorate Phabricator T42618. jquery.tablesorter: Add support for a "fixed" column of row numbers. One stalled patch there kept rows aligned even with row laddering.
This is about keeping the rows aligned between the fixed row number column and the table to its right. {{Static column begin}} does this best when there is a column header in the main table that spans all the header rows.
Sometimes you have to create that row-spanning header cell. For example; see the top table in this specific revision of a Wikipedia article.
The blank row-spanning header cell and column has been added on the right side:
|
|
header-lines=10 allows readers to zoom the text alone to very high levels and not break row alignment. For example; in Firefox browser go to:
view menu > zoom > zoom text only > zoom in.
The blank column is made invisible by adding style="padding-left:0;padding-right:0;"
to its header.
|
|
Here is how that empty row-spanning header is formatted so that header-lines=10
works:
!rowspan=4 class=unsortable style="padding-left:0;padding-right:0;"|<br><br><br><br><br><br><br><br><br><br>
Here is the header wikitext:
{{Rank| rows=2| header-text=Row| header-lines=10| text-align=right| caption=Incarceration rates by state.}}
{|class="wikitable nowrap sortable mw-datatable" border=1 style=text-align:right;
|-valign=bottom
!Jurisdiction
!Year-end<br>2016. In<br>prison<br>or jail
!2016<br>rate per<br>100,000<br>adults
!2016<br>rate per<br>100,000<br>of all ages
!rowspan=4 class=unsortable |<br><br><br><br><br><br><br><br><br><br><!--The spanning header cell is needed for {{Rank}} row alignment.-->
|-
See also[edit]
- Template:Static column row – Template for creating one table row, which this template uses.
The above documentation is transcluded from Template:Static column begin/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |