When we define a table in Asciidoctor the columns all have the same width and the table will the whole width of the page. Of course we can change this when we define the table. We can change the table width with the
width attribute. We specify the column width with the
First we will change the width of the columns. We can specify proportional integer values or a percentage to specify the width of a column. In the following sample Asciidoctor file we use proportional values in the first table. The first column has value
1 and the second column value
3. This means the second column should be 3 times as wide as the first column. In the second table the column width is defined with percentage values. The first column should occupy
60% of the table width and the last column the rest.
// Define table with proportional column width. .Table with relative column widths (1,3) [cols="1,3"] |=== | Name | Description | Asciidoctor | Awesome way to write documentation |=== // Define table with column width as percentage values. .Table with percentage column widths (60%,40%) [cols="60%,40%"] |=== | Name | Description | Asciidoctor | Awesome way to write documentation |===
When we transform the Asciidoctor source to HTML we get the following result:
We see in the examples that the width of the table is the same as the width of the page. To make a smaller table we set the
width attribute for a table. The value must be a percentage. Let's create a sample Asciidoctor file and define a table with a width of
// Define table with default width for comparison. .Table full width (default) |=== | Name | Description | Asciidoctor | Awesome way to write documentation |=== // Define new table and set width to 50%. .Table half width (50%) [width="50%"] |=== | Name | Description | Asciidoctor | Awesome way to write documentation |===
And if we look at the generated HTML for example we can see the second table is half the width of the first:
Written with Asciidoctor 1.5.1.