模板:Table alignment

文件圖示 模板文件[檢視] [編輯] [歷史] [清除快取]

作用

編輯

以較少的代碼簡便地對齊表格中的列。

用法

編輯

放置{{Table alignment}}在表格之前,然後增加表格的class。

類名 效果
defaultleft 所有單元格默認左對齊
defaultcenter 所有單元格默認居中對齊
defaultright 所有單元格默認右對齊
colNleft 左對齊第N列中的單元格
colNcenter 居中對齊第N列中的單元格
colNright 右對齊第N列中的單元格
lastcolNleft 左對齊倒數第N列中的單元格
lastcolNcenter 居中對齊倒數第N列中的單元格
lastcolNright 右對齊倒數第N列中的單元格
  • col類覆蓋default類的效果。
  • 不使用wikitable類時,col和default類會作用於標題單元格;而使用wikitable類時,除非單獨調整,否則標題單元格內容始終居中。
  • 有合併單元格(使用了rowspan或colspan)的表格,如果col類效果不佳(對齊效果錯位),請嘗試使用lastcol指定倒數第N列的對齊方式,否則只能對單個單元格手動調整。
  • 同一條目中放置一次{{Table alignment}}即可。
  • 最多支持29列,更多的列無法進行對齊。

示例

編輯

下面的示例將第一列左對齊,第四列右對齊,其餘列居中對齊。

{{Table alignment}}
{| class="wikitable defaultcenter col1left col4right"
!项目1
!项目2
!项目3
!项目4
|-
|AAAAAA
|100-200
|3-4
|53.43
|-
|BBB
|5-6
|7-8
|5563.35
|-
|CC
|9-10
|113-125
|322313.00
|}
項目1 項目2 項目3 項目4
AAAAAA 100-200 3-4 53.43
BBB 5-6 7-8 5563.35
CC 9-10 113-125 322313.00

參見

編輯
  • {{Column style}}
  • {{shy}} – Can be used to help narrow columns by adding a soft hyphen to a word to allow it to wrap.
  • {{sticky header}} - Makes column headers stick to the top of the page while scrolling through table data.
  • {{sort under}} - moves the sorting arrows under the headers.
  • {{row hover highlight}} - adds row hover highlighting, and option for white background.
  • {{static row numbers}} - adds a column of row numbers to a table.