列宽
使用整数分配列宽
为了给表格中的列分配宽度,设置 cols
属性并给它分配一个由逗号分隔的整数列表作为列说明符。
|===
[cols="2,1,3"]
|Column 1 |Column 2 |Column 3
|This column has a proportional width of 2
|This column has a proportional width of 1
|This column has a proportional width of 3
|===
如下所示,各列根据它们的比例宽度跨越页面的宽度。
.Result of 使用整数分配列宽 [cols="2,1,3"] |
Column 1 |
Column 2 |
Column 3 |
This column has a proportional width of 2 |
This column has a proportional width of 1 |
This column has a proportional width of 3 |
增加或减少列的宽度
|===
[cols="6,1,3"]
|Column 1 |Column 2 |Column 3
|This column has a proportional width of 6
|This column has a proportional width of 1
|This column has a proportional width of 3
|===
下面,增加列的宽度的结果显示,第1列现在比第3列宽得多。
.Result of 增加列的宽度 [cols="6,1,3"] |
Column 1 |
Column 2 |
Column 3 |
This column has a proportional width of 6 |
This column has a proportional width of 1 |
This column has a proportional width of 3 |
要减小列的宽度,使用更小的整数在其指定符中。在减小列的宽度中,让我们通过将列3的宽度从`3`减小到`2`来使其宽度变小,但不要像列2那样小。
|===
[cols="6,1,2"]
|Column 1 |Column 2 |Column 3
|This column has a proportional width of 6
|This column has a proportional width of 1
|This column has a proportional width of 2
|===
下表中的列根据它们各自的比例宽度调整,以适应页面的宽度。
.Result of 减小列的宽度 [cols="6,1,2"] |
Column 1 |
Column 2 |
Column 3 |
This column has a proportional width of 6 |
This column has a proportional width of 1 |
This column has a proportional width of 2 |
使用百分比值改变列宽。
列宽可以分配一个百分比,范围是 1%
到 100%
。和整数值一样,设置 cols
并使用百分比,将其分配一个逗号分隔的列指定符列表。
|===
[cols="15%,30%,55%"]
|列 1 |列 2 |列 3
|这一列的宽度是15%
|这一列的宽度是30%
|这一列的宽度是55%
|===
如下表所示,根据分配给它们的列说明符的百分比,各列会跨越整个页面的宽度进行延伸。
.Result of 使用百分比指定列宽 [cols="15%,30%,55%"] |
Column 1 |
Column 2 |
Column 3 |
This column has a width of 15% |
This column has a width of 30% |
This column has a width of 55% |
在为`cols`指定百分比时,你不必包括百分号(%
)。例如,[cols="15%,30%,55%"]`和
[cols="15,30,55"]`都是有效的。