@@ -66,15 +66,17 @@ You can add a table separator anywhere in the output by passing an instance of
66
66
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
67
67
+---------------+--------------------------+------------------+
68
68
69
- The width of the columns are automatically set using the width of their contents
70
- by default. You can control the minimum widths via :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnWidths `::
69
+ By default the width of the columns is calculated automatically based on their
70
+ contents. Use the :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnWidths `
71
+ method to set the column widths explicitly::
71
72
72
- // the widths will expand to be bigger if necessary
73
- // here, the left two columns will be 13 & 24 characters to fit their content
73
+ // ...
74
74
$table->setColumnWidths(array(10, 0, 30));
75
75
$table->render();
76
-
77
- This code results in:
76
+
77
+ In this example, the first column width will be ``10 ``, the last column width
78
+ will be ``30 `` and the second column width will be calculated automatically
79
+ because of the ``0 `` value. The output of this command will be:
78
80
79
81
.. code-block :: text
80
82
@@ -88,6 +90,21 @@ This code results in:
88
90
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
89
91
+---------------+--------------------------+--------------------------------+
90
92
93
+ Note that the defined column widths are always considered as the minimum column
94
+ widths. If the contents don't fit, the given column width is increased up to the
95
+ longest content length. That's why in the previous example the first column has
96
+ a ``13 `` character length although the user defined ``10 `` as its width.
97
+
98
+ You can also set the width individually for each column with the
99
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnWidth ` method.
100
+ Its first argument is the column index (starting from ``0 ``) and the second
101
+ argument is the column width::
102
+
103
+ // ...
104
+ $table->setColumnWidth(0, 10);
105
+ $table->setColumnWidth(2, 30);
106
+ $table->render();
107
+
91
108
The table style can be changed to any built-in styles via
92
109
:method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setStyle `::
93
110
0 commit comments