Help:Table/Advanced: Difference between revisions

Content deleted Content added
Collapsible tables: move {{shortcut}} up (as it redirects to the entire section rather than an anchor within it)
 
(14 intermediate revisions by 3 users not shown)
Line 538:
 
===Horizontal scrolling table===
{{See also|Help:Table#Overflowing tables}}
Adding {{code|-x}} to {{code|overflow:auto}} → {{code|overflow-x:auto}} forces overflowing table data to fit within page's width margin or otherwise predetermined wiki markup.
 
Line 570 ⟶ 571:
:'''''History:''' See [[Wikipedia:Village pump (technical)/Archive 208#Vector 2022. Sticky page title covers top 2 lines of sticky table headers|most recent Village Pump discussion]]. And other archived discussions: [[Wikipedia:Village pump (technical)/Archive 206#Vertical scrollable table with sticky headers|1.]] [[Wikipedia talk:Reliable sources/Perennial sources/Archive 3#Technical idea: make the header row of the table sticky|2.]] [[Help talk:Table#Scrolling tables and sticky headers|3.]] [[Help talk:Table/Archive 8#Sticky table headers?|4.]] [[Wikipedia:Village pump (technical)/Archive 170#Sticky table headers|5.]] See [[Phab:T42763]]. See also: [[Meta: Community Wishlist Survey 2022/Reading/floating table headers]] and [[meta:Community Wishlist Survey 2021/Reading/Enable sticky table headers]].''
 
A'''[[Template:Sticky header]]''' creates a sticky scrolling table in the sense of the vertical scrollbar for the whole page. When you scroll the page the table headers stay visible when the table goes beyond the top of the screen. See also: '''[[Template:Sticky table start]]'''. It has an option for side sticky headers too. It puts the table in a scrollbox, and the scrollbars are part of that box.
 
See '''[[Template:{{tl|Sticky header]]}}''' for examples, more info, and specialized cases.below:
 
<div style="display: inline-grid; vertical-align:top;">
Line 645 ⟶ 646:
*[[Template talk:COVID-19 pandemic death rates#Automation of updates]].
*[[Template talk:COVID-19 vaccination data#Automation of updates to this template]].
 
== Transclude a table from another page ==
 
A table can be put in a template. For example, see [https://en.wikipedia.org/wiki/Special:PrefixIndex?prefix=Template%3AList+of+countries+by+life+expectancy%2F&namespace=0 this list of life expectancy table template subpages]. You can search for template subpages:
*[[Special:PrefixIndex]] - choose the template namespace.
 
{{tl|Excerpt}} is the simplest tool for transcluding a table that is not in a template. Go there for many options. The simplest method:
<syntaxhighlight lang=wikitext>
{{Excerpt|Page source of table|Section with the table|this=This table is}}
</syntaxhighlight>
 
It transcludes the table to wherever it is placed. It adds the following indented note above it in italics. The page section is linked, and there is an edit link for the source page:
:''This table is an excerpt from Page source of table § Section with the table. [edit]''
 
A hidden note <code><nowiki><!-- NOTE --></nowiki></code> just above the transcluded table is helpful. Such as:
:Table below is currently transcluded from here: <nowiki>https://en.wikipedia.org/wiki/Page_source_of_table#Section_with_the_table</nowiki>. If the source article or section name is changed, then the transclusion code below must also be changed.
 
A hidden note at the source section is helpful too. Such as:
:Table below is transcluded into another page: <nowiki>https://en.wikipedia.org/wiki/Page_with_transcluded_table#Section_with_the_table</nowiki>. Nothing needs to be added here for this to work. As long as the table remains in its own section, and that section name remains the same, then the transclusion works. If the section name here changes, then please change it in the <nowiki>{{excerpt}}</nowiki> template there.
 
All broken excerpts are automatically tracked at [[:Category:Articles with broken excerpts]] and regularly fixed.
 
== Sortable tables ==
Line 655 ⟶ 677:
== Collapsible tables ==
{{see also|Help:Collapsing#Collapsible tables|mw:Manual:Collapsible elements}}
{{shortcut|WP:TABLECOLLAPSE}}
 
Classes can also be used to collapse tables, so they are hidden by default. Use the class {{nowrap|<code>mw-collapsible</code>}} to enable collapsing behaviour. Collapsible tables can be sortable, too, by also including the <code>sortable</code> class {{See below|{{section link||Sortable tables}}}}. By default, a collapsible table begins expanded. To change this, add the additional class {{nowrap|<code>mw-collapsed</code>}}. Alternatively, you can add <code>autocollapse</code>, instead of {{nowrap|<code>mw-collapsed</code>}}, which will automatically collapse the table if two or more collapsible elements are present on the page.
Line 747 ⟶ 770:
</syntaxhighlight></div>
<div style="display:inline-table; border: 2px solid lime; padding: 0.5em;">
'''Rendered result.<br>Click "hide" to seecollapse'''
----
{| class="wikitable mw-collapsible"
Line 760 ⟶ 783:
</div>
<div style="display:inline-table; border: 2px solid lime; padding: 0.5em;">
'''Rendered result<br>(without <nowiki>{{nowrap}}</nowiki>.<br>Click "hide" to seecollapse'''
----
{| class="wikitable mw-collapsible"
Line 789 ⟶ 812:
</syntaxhighlight></div>
<div style="display:inline-table; border: 2px solid lime; padding: 0.5em;">
'''Rendered result.<br>Click "hideshow" to see'''
----
{| class="wikitable mw-collapsible mw-collapsed"
Line 802 ⟶ 825:
</div>
<div style="display:inline-table; border: 2px solid lime; padding: 0.5em;">
'''Rendered result<br>(without <nowiki>{{nowrap}}</nowiki>.<br>Click "hideshow" to see'''
----
{| class="wikitable mw-collapsible mw-collapsed"
Line 817 ⟶ 840:
'''Sorting and collapsing'''
 
{{shortcut|WP:TABLECOLLAPSE}}
It is possible to collapse a sortable table. To do so, you need to use this code:
:<code>'''class="wikitable sortable mw-collapsible"'''</code>
Line 886 ⟶ 908:
{{Hatnote|'''Templates:''' {{t|background color}}, {{t|font color}}, {{t|Coltit}}, {{t|Color}}.}}
{{Hatnote|'''Value-dependent color:''' {{t|cell color}}.}}
{{Hatnote| '''Night mode:''' [[mw:Recommendations for night mode compatibility on Wikimedia wikis]].}}
 
Background colors are common in table cells. In many sports articles for example. See '''[[List of top-division football clubs in UEFA countries|here]].''' For the accessibility reasons stated in [[WP:COLOR]], information should not be communicated by the use of color alone.
Line 968 ⟶ 991:
 
In dark mode in article namespace table cells with background colors have black underlined links. For example:
*[[List of top-division football clubs in UEFA countries#Spain]] - scroll down a little to the table.
So any cell with [[WCAG]]-acceptable link color contrast in light mode has even better link color contrast in dark mode.
{{tracked|T376931}}
Line 981 ⟶ 1,004:
There are many off-wiki tables with useful coloring that meet [[WCAG]] access standards. Currently, there does not seem to be a way to copy those tables to a wiki and keep styling such as colors (background or text color). It is possible to convert PDF tables to Excel and keep the colors. Or to HTML tables and keep the colors. But there does not seem to be a way to copy any of those colored tables (PDF, Excel, HTML, etc.) to a wiki. If there is a way, please leave a note on [[Help talk:Table]].
 
If desired one can keep the coloring by copying the table as an image. This may be necessary for frequently updated colored tables where it would be too time consuming to add color to many cells after each update. There is no problem with copyright for most data tables, colored or not. They are in the public ___domain. See [[Commons:Template:PD-chart]]. Go here for more info:
*[[Help:Table#Public ___domain image tables]]
 
== Other table syntax ==
Line 1,091 ⟶ 1,115:
== See also ==
 
*[[Help:Table]] for general information about using tables. It also has many links in its "{{slink|Help:Table|See also" and "|External links" sections.|nopage=y}}, Ratherwhich thanare duplicatingnot themduplicated here.
 
{{Help navigation}}