Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Help:Table
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Row operations == Table rows are added after the [[#Wikicode syntax tutorial|§ table start indicator]], and after any optional [[#Whole table operations|§ whole table markup]] such as a caption, table summary, or [[#Setting column widths. Other methods|§ column scope]] attributes. === Starting a new row === To start a new '''table [[Row (database)|row]]''', type a vertical bar and a [[hyphen]] on its own line: "<code>'''|-'''</code>". The codes for the cells in that row start on the next line. An <code>id</code> for [[#Link directly to a row|§ anchoring in-links]], and [[#Row style|§ row style]] may be included on the same line. <syntaxhighlight lang=wikitext class=gridbox> {| |+ The table's caption |- row styling goes here row code goes here |} </syntaxhighlight> === Row style === {{Further|#Height|#Setting borders}} Row style (height, width, borders, text alignment, background color, bolding, italics, etc.) may be added to a wikitable row by appending [[CSS#Properties|CSS style properties]] to the row start line after the <code>'''|-'''</code> indicator. Here is an example increasing the height of the middle row. The top row has italic text. The last row has bold text and a yellow background: <div class=box> '''Wikitext''' <syntaxhighlight lang=wikitext highlight=4,6,8> {| class=wikitable |- ! Left !! Center !! Right |- style=font-style:italic; | Top left || Top center || Top right |- style=height:9em; id=mid | Middle left || Middle center || Middle right |- style="font-weight:bold; background-color:yellow;" | Bottom left || Bottom center || Bottom right |} </syntaxhighlight></div> <div class=box> '''Produces''' {| class=wikitable |- ! Left !! Center !! Right |- style=font-style:italic; | Top left || Top center || Top right |- style=height:9em; id=mid | Middle left || Middle center || Middle right |- style="font-weight:bold; background-color:yellow;" | Bottom left || Bottom center || Bottom right |} </div> Note that the row also contains an <code>id</code> attribute; this will be explained later in the section about [[#Link directly to a row|linking directly to a row]]. === Row headers === Note that with row headers you need to use a separate row in the wikitext for the row header cell. Here below is what a table looks like if the data cell wikitext is on the same line as the row header wikitext. Note that the data cell text is bolded, and the data cell backgrounds are the same shade of gray as the column and row headers. <div class="box"> '''Wikitext''' <syntaxhighlight lang="wikitext" highlight=5,7> {| class=wikitable |+ The table's caption ! Column 1 !!Column 2 !!Column 3 |- ! Row header 1 || Cell 2 || Cell 3 |- ! Row header A || Cell B || Cell C |} </syntaxhighlight></div> <div class="box"> '''Produces''' {| class=wikitable |+ The table's caption ! Column 1 !!Column 2 !!Column 3 |- ! Row header 1 || Cell 2 || Cell 3 |- ! Row header A || Cell B || Cell C |} </div> Here is the table with a '''separate wikitext row for each row header cell.''' The data cells have plain unbolded text, and a lighter background. <div class="box"> '''Wikitext''' <syntaxhighlight lang="wikitext" highlight=5,8> {| class=wikitable |+ The table's caption ! Column 1 !!Column 2 !!Column 3 |- ! Row header 1 | Cell 2 || Cell 3 |- ! Row header A | Cell B || Cell C |} </syntaxhighlight></div> <div class="box"> '''Produces''' {| class=wikitable |+ The table's caption ! Column 1 !!Column 2 !!Column 3 |- ! Row header 1 | Cell 2 || Cell 3 |- ! Row header A | Cell B || Cell C |} </div> === Row numbers === Table rows may be numbered with the assistance of templates provided for the purpose. See [[Help:Sortable tables]] sections on row numbers, and these templates: * {{tl|Static row numbers}} * {{tl|Row numbers}} === Link directly to a row === {{sh|WP:ROWLINK|WP:LINKROW|Help:ROWANCHOR}} You can link directly to a row in a wikicode table, by including an <code>id</code> attribute on the line with the [[#Markup|§ row start]] indicator whose value is the [[WP:ANCHOR|anchor]] for the link. For example, you could code: :<code><nowiki>|- id="mid"</nowiki></code> and then link to it using <code><nowiki>The [[#mid|middle row]] is the tallest one.</nowiki></code> which produces: : The [[#mid|middle row]] is the tallest one. ''(Click to try it out!){{hairspace}}'' === Row template === {{For|adding a dynamic row number as a table column|#Row numbers}} Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, may have much in common, e.g.: * the basic code for a table row * code for color, alignment, and sorting mode * fixed texts such as units * special formats for sorting In such a case, it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages: * easily changing the order of columns, or removing a column * easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls) * computing fields from other fields, e.g. population density from population and area * duplicating content and providing span tags with <code>display: none;</code> for the purpose of having one format for [[Help:Sortable tables|sorting]] and another for display * easy specification of a format for a whole column, such as color and alignment Example: Using {{tlx|Help:Table/example row template}} <div class="box"> '''Wikitext''' <syntaxhighlight lang="wikitext" style="display: inline-block;"> {| class="wikitable sortable" |- ! scope=col | a ! scope=col | b ! scope=col | a/b {{Help:Table/example row template| 50|200}} {{Help:Table/example row template| 8| 11}} {{Help:Table/example row template|1000| 81}} |} </syntaxhighlight></div> <div class="box"> '''Produces''' {| class="wikitable sortable" |- ! scope=col | a ! scope=col | b ! scope=col | a/b {{Help:Table/example row template| 50|200}} {{Help:Table/example row template| 8| 11}} {{Help:Table/example row template|1000| 81}} |} </div> === Conditional table row === {{main|Wikipedia:Conditional tables}} For a conditional row in a table, we can have: <div class="box"> '''Wikitext''' <syntaxhighlight lang="wikitext" style="display: inline-block;"> {| class=wikitable {{ #if:1|{{!}}- ! scope=row {{!}} row one, column one {{!}}row one, column two}} {{ #if: |{{!}}- ! scope=row {{!}} row two, column one {{!}}row two, column two}} |- ! scope=row {{!}} row three, column one | row three, column two |} </syntaxhighlight></div> <div class="box"> '''Produces''' {| class=wikitable <!-- Row one is shown because the '1' evaluates to TRUE --> {{ #if:1|{{!}}- ! scope=row {{!}} row one, column one <!-- {{!}}'s get evaluated to the pipe character '|', i.e. template:! just contains '|' --> {{!}}row one, column two}} <!-- Row two NOT shown because the space between the ':' and the '|' evaluates to FALSE --> {{ #if: |{{!}}- ! scope=row {{!}} row two, column one {{!}}row two, column two}} <!-- Row three is shown --> |- ! scope=row {{!}} row three, column one | row three, column two |} </div> With comments to explain how it works, where note how the second row is missing: <div class="box"> '''Wikitext''' <syntaxhighlight lang="wikitext" style="display: inline-block;"> {| class=wikitable <!-- Row one is shown because the '1' evaluates to TRUE. --> {{ #if:1|{{!}}- ! scope=row {{!}} row one, column one <!-- Any {{!}}'s are evaluated to the pipe character '|' since the template '!' just contains '|'. --> {{!}}row one, column two}} <!-- Row two is NOT shown because the space between the ':' and the '|' evaluates to FALSE. --> {{ #if: |{{!}}- ! scope=row {{!}} row two, column one {{!}}row two, column two}} <!-- Row three is shown. --> |- ! scope=row {{!}} row three, column one | row three, column two |} </syntaxhighlight></div> <div class="box"> '''Produces''' {| class=wikitable <!-- Row one is shown because the '1' evaluates to TRUE --> {{ #if:1|{{!}}- ! scope=row {{!}} row one, column one <!-- {{!}}'s get evaluated to the pipe character '|', i.e. template:! just contains '|' --> {{!}}row one, column two}} <!-- Row two NOT shown because the space between the ':' and the '|' evaluates to FALSE --> {{ #if: |{{!}}- ! scope=row {{!}} row two, column one {{!}}row two, column two}} <!-- Row three is shown --> |- ! scope=row {{!}} row three, column one | row three, column two |} </div>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)