Template:Truthtable

Template page
Revision as of 02:23, 1 November 2023 by Gelthor (talk | contribs) (Fixed wide option)


This page has been transcluded from Template:Truthtable/Documentation.


Template to put at the top of table declarations to standardise the appearance of truth tables. By default it will place the table "floating" on the left hand side. If you want the table to apear on the right side then use: {{truthtable|float=right}}. If you want the table to fill the whole width of the page, call the template as follows: {{truthtable|wide=1}}. Additionally, you can mark the table as sortable (i.e. if it's a table of sortable values, such as {{yes}} or {{no}}), by using the "sortable" parameter: {{truthtable|sortable=1}}. Text can be left-aligned in the table using {{truthtable|text left=1}}. Finally, extra styling can be added using the "style" parameter.

Using the "wide" parameter is discouraged for normal situations: Truth tables should be left- or right-floated if that makes things look better.

Parameters

  • wide: If a value is given (1, 0 or anything) it will make the table stretch to fit the area it is contained in.
  • sortable: If a value is given, it allows columns to be sorted by clicking on the little icon within the header cell at the top of the column.
    • To change individual columns to be unsortable (for instance for images), use the "unsortable" class on the header cell.
  • text left: If a value is given, text will be left-aligned, otherwise centre-aligned by default.
  • float: A side on which to float the table ("left", "right" and "none" are the allowed values). If neither "float" nor "wide" are given "left" is the default.
  • style: Additional style values are allowed; usage is simply the CSS values not surrounded by quotes.
  • class: Additional CSS class names (separated by spaces) to apply to the table.

Example

Not Wide

{| {{truthtable}}
! Input One !! Input Two !! Output
|-
| {{No}}|| {{No}}|| {{Yes}}
|-
| {{No}}|| {{Yes}}|| {{Yes}}
|-
| {{Yes}}|| {{No}}|| {{Yes}}
|-
| {{Yes}}|| {{Yes}}|| {{No}}
|}
Input One Input Two Output
No No Yes
No Yes Yes
Yes No Yes
Yes Yes No

Wide

{| {{truthtable|wide=1}}
! Input One !! Input Two !! Output
|-
| {{No}}|| {{No}}|| {{Yes}}
|-
| {{No}}|| {{Yes}}|| {{Yes}}
|-
| {{Yes}}|| {{No}}|| {{Yes}}
|-
| {{Yes}}|| {{Yes}}|| {{No}}
|}
Input One Input Two Output
No No Yes
No Yes Yes
Yes No Yes
Yes Yes No

Symbols

{| {{truthtable}}
! A !! NOT(A)
|-
| {{Off}} || {{On}}
|-
| {{On}} || {{Off}}
|}
A NOT(A)

Full example

{| {{truthtable|float=right|sortable=1|text left=1|style=font-size:1.5em}}
|+ NAND Gate Truth Table
! Input One !! Input Two !! class="unsortable" | Output
|-
|data-sort-value="0"| {{off}}|| data-sort-value="0"| {{off}}  || {{on}} 
|-
|data-sort-value="0"| {{off}}|| data-sort-value="1"| {{on}}  || {{on}} 
|-
|data-sort-value="1"| {{on}} || data-sort-value="0"| {{off}} || {{on}} 
|-
|data-sort-value="1"| {{on}} || data-sort-value="1"|  {{on}}  || {{off}}
|}
NAND Gate Truth Table
Input One Input Two Output